Docker Laravel Map folder

0

Good afternoon. I'm trying to create a development environment with sublime, docker, laravel. The image I downloaded from the hub docker, comes with debian, php, laravel already isntalados. The host is windows.

But when I execute this command to map the host folder with the container, the container folder is overwritten by the clean host folder: docker run -p 80:80 -p 443: 443 -v \ folder \ windows \ workspace \ app: / var / www / laravel / app / -v \ folder \ windows \ workspace \ public: / var / www / laravel / public / -d eboraas / laravel I know this functionality of the command is normal. I would like to sync the container folder on the host and continue developing the application on top of this created environment.

Is this the way docker is normally used for development?

Thanks for your attention.

    
asked by anonymous 13.09.2017 / 20:54

1 answer

1

When you run docker run -v pasta_host:pasta_contêiner you are mounting a directory on the container before it runs.

When you mount a folder, you end up hiding what was in it before the assembly and that can only be accessed the moment it is disassembled, in the case of Docker it is only disassembled at the time the container dies.

If you mount an empty directory over a directory that had files in the container's initial image, you will not see these files in the container.

I'll give you an interesting example of how this plays pieces. Let's think about the official image of Wordpress.

When you download the official Wordpress image it still does not contain Wordpress! It contains the web server, PHP and all the modules needed to run it. Copying of the files is done by downloading the official website only at the beginning of the container run, it is verified that the / var / www / html folder is empty.

If the official Wordpress image contained the Wordpress files in the / var / www / html folder before the container was run and the user made the / var / www / html folder volume to a local folder on the empty host, it would be mounted above the files and when trying to access by the browser we would see the index of the web server showing an empty folder and not the initial installation screen of Wordpress.

To resolve these cases, I suggest you upload the docker image first without mounting the folder and then run the command:

docker cp CONTEINER:/ponto/de/montagem/interno ponto_de_montagem_externo

After that you kill the container and reexecute it with the mount (-v).

    
23.01.2018 / 20:44