EDIT: I'm not longer using docker so I'll not be able to test answers to this question
thanks to all for the suggestions!
TL;DR: can you point me to a simple example of an image that writes changes to a volume shared between the container and the host filesystem?
Hi,
I have some trouble understanding how volumes work.
I've read the Dockerfile reference and also understanding volumes
What I'm trying to do
- I have an image that makes a composer installation of wordpress on RUN to /var/tmp/html
- then ONBUILD I use some information from docker-compose.yml ENVIRONMENT variables to make some more operations to /var/tmp/html
- As the last step I want everything to be copied to /var/www/html and have it acessessible from the composer (be able to run apache pointing to those files) and from the local filesystem (I will code things to this html directory)
What I have right now
Test 1
The link above is a link to the specific version on github of those files
This test is just everything to install wordpress without any volume information
Result
Bashing into the image and listing /var/www/html
I get:
root@4484ccdb63ca:/var/www/html# ls -al
total 32
drwxr-xr-x 6 www-data www-data 4096 Jan 21 11:45 .
drwxr-xr-x 6 root root 4096 Jan 21 11:45 ..
-rw-r--r-- 1 www-data www-data 10 Jan 21 10:47 .gitignore
-rw-r--r-- 1 www-data www-data 138 Jan 21 10:47 composer.json
-rw-r--r-- 1 www-data www-data 3718 Jan 21 10:47 composer.lock
-rw-r--r-- 1 www-data www-data 428 Jan 21 10:47 index.php
drwxr-xr-x 6 www-data www-data 4096 Jan 21 11:45 vendor
drwxr-xr-x 8 www-data www-data 4096 Jan 21 11:45 wordpress
wich is ok
and listing ./html on the local filesystem I get
total 0
drwxr-xr-x 3 miqueladell staff 102 Jan 21 10:33 .
drwxr-xr-x 11 miqueladell staff 374 Jan 21 13:04 ..
-rw-r--r-- 1 miqueladell staff 0 Jan 21 10:33 foo
which is wrong but totally expected. The files are ok on the container but have nothing to do outside the container because I did not provide any volume information.
Test 2
The link above is a link to the specific version on github of those files
adds VOLUME on Dockerfile and docker-compose.yml
this is a paste of the diff
Dockerfile
- # VOLUME /var/www/html/
+ VOLUME /var/www/html/
docker-compose.yml
- # volumes:
- # - .html:/var/www/html/
+ volumes:
+ - ./html:/var/www/html/
The result of building the image and running the cointainer is both empty an empty html directory on the container and no change to the local filesystem
Thanks!
EDIT: I've created a minimal failing version of this question: How to get contents generated by a docker container on the local fileystem (minimal failing example)