Docker Laravel Map folder

Asked

Viewed 278 times

0

Good afternoon. I’m trying to create a development environment with sublime, Docker, Portable. The image that I downloaded from the Docker hub, comes with debian, php, already isontalized Laravel. The host is windows.

But when I run this command to map the host folder to the container, the container folder is subscribed by the host folder that it cleans: 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 command feature is normal. I would like to synchronize the container folder on the host and continue the application development on top of this created environment.

This is how Docker is typically used for development?

Thank you for your attention.

  • One way that I found but I don’t know if it’s right was to copy the project folder that is in the container to the host and then run the command up.

1 answer

1

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

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

If you mount an empty directory on top of a directory that had files in the initial container image, you will not see these files in the container.

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

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

If by any chance the official Wordpress image contained the Wordpress files in the /var/www/html folder before running the container and the user made volume from the /var/www/html folder to a local folder on the empty host, it would be mounted over the files and when trying to access through the browser we would see the web server index showing an empty folder and not the Wordpress installation home screen.

To solve these cases, I suggest that 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 replay with the assembly (-v).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.