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).
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.
– Magno Malkut