Docker Volumes
New docker volume is created using the command:
docker volume create my_volume
The container is run with my_volume
mounted inside the container:
docker run --mount source=my_volume,destination=/usr/share/nginx/html/ -p 8080:80 nginx
The nginx welcome page is visible.
A minimal index.html
is created.
docker cp index.html infallible_neumann:/tmp/vol/
Successfully copied 2.048kB to infallible_neumann:/tmp/vol/
The updated index.html
is accesible.
docker stop infallible_neumann
docker rm infallible_neumann
docker run --mount source=my_volume,destination=/usr/local/apache2/htdocs/ -p 8081:80 httpd
The httpd default page is accesible.
File created about.html
docker cp about.html pensive_sinoussi:/usr/local/apache2/htdocs/
Successfully copied 2.048kB to pensive_sinoussi:/usr/local/apache2/htdocs/
about.html is accessible on /about.html
docker stop pensive_sinoussi docker rm pensive_sinoussi
The files are available:
sudo ls /var/lib/docker/volumes/my_volume/_data
about.html index.html
docker volume rm my_volume