Gii Code Generator creates files in docker container only

Hi everyone

I have been trying to setup Yii2 on a docker container. So far it worked great and I managed to make it run smoothly so far. Whenever I generate code with Gii however, the generated files only appear within the docker container in

/usr/local/myapp/php/webapp/models

However, I need to make the generated code appear on my local machine and mount it into the docker container after I made my adjustments to it.

To wrap it up, I have two questions here:
First, is how do I make the generated code appear on my local machine?
Second, why does Gii generates the code on the container? I do not quite understand the behavior here.

The files MUST be generated into your computer, since docker maps the container content to a folder in your local computer (unless configured otherwise).

What could be happening is that you don’t have permissions on those generated files/folders, since it will be generated with the container permissions.

Those are generated in the container because you are probably running the command from within the container.
For more info, you should take a look at docker documentation.

Hi,
you have to mount your local web folder into the container.
This can be done with docker volumes.

If you are using docker-compose you have to set something like this:

services:
    php:
      image:xxx-php:v1.2.0-stable
      env_file:
            - .env
      networks:
          - ${NETWORK_NAME}
      ports:
      - "9000:9000"
      volumes: 
         - ./app/:/var/www/html/**

Where “app” is the source directory (where you have yii source code) underneath docker-compose.yml and /var/www/html the directory inside the container
h

Hi @bpanatta thanks for your reply. I had permission but somehow the generated files only were created on the container, since my application run on the container.

What I did to solve the problem was kind of primitiv, but it worked out somehow. I generated the code in the container and than simply copied the generated files into the directory that would be mounted into the container afterwards. A little bit of a struggle to do this way, but it worked.

Hi @hyde82
Thanks a lot for the reply. I actually managed to get the files to the right place, even tho I might have done some strange things to be able to do so.