docker volume list
: listdocker volume inspect VOL_ID
: inspectdocker volume create VOL_ID
: create
Mount host filesystem to container volume
docker container run -it --rm -v VOL_ID:path ubuntu:xenial
: attach a volume to a containerdocker container run ... -v $(pwd):path...
: sync local dir to the containerdocker container run ... -v $(pwd):path:rw ...
: setup rw permission for the volumedocker container run ... -v $(pwd):path:ro ...
: setup ro permission for the volume
docker run -d -p 80:80 -v VOL_ID:/usr/local/apache2/htdocs httpd
docker run -d -p 80:80 -v /usr/local/apache2/htdocs httpd
: a random volume will be created in/var/lib/docker/volumes/XXX/_data
echo "xxx" > /var/lib/docker/volumes/XXX/_data
docker volume create vol1
docker container run -it --rm -v vol1:/data ubuntu:xenial /bin/bash
- in the container
ls /data
: check the path in the containertouch /data/xxx
exit
docker ps
: the container is killeddocker container run -it --rm -v vol1:/data ubuntu:xenial /bin/bash
: create a new container- in the container
ls /data
: check the previously createdxxx
file in the container