知乎專欄 | 多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者” |
docker volume ls
# docker volume ls DRIVER VOLUME NAME local dbac41b6de88c75d2932d5949367b17f347f482977d508195375dbc71518ab27
# docker volume create --name WebVolume1 WebVolume1
# docker volume ls DRIVER VOLUME NAME local WebVolume1 local dbac41b6de88c75d2932d5949367b17f347f482977d508195375dbc71518ab27
# docker run -ti --rm -v WebVolume1:/www ubuntu # docker run -ti --rm -v WebVolume1:/www docker.io/centos:7
查看卷的掛載情況
# df | grep /www /dev/vda1 20510332 7943940 11501484 41% /www
創建測試檔案
# mkdir -p /www/netkiller.cn/www.netkiller.cn # echo Helloworld > /www/netkiller.cn/www.netkiller.cn/index.html # cat /www/netkiller.cn/www.netkiller.cn/index.html Helloworld # exit exit
# docker volume inspect WebVolume1 [ { "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/WebVolume1/_data", "Name": "WebVolume1", "Options": {}, "Scope": "local" } ]
# docker volume prune WARNING! This will remove all volumes not used by at least one container. Are you sure you want to continue? [y/N] y Deleted Volumes: WebVolume1 3fd379f8c2cf8727d2e83e84e434ea1f122016957bd7cf78a0f05b6e5a69cf2b app Total reclaimed space: 11 B
容器一
# docker run -ti --name=Container1 -v DataVolume1:/opt/data ubuntu
容器二
# docker run -ti --name=Container2 --volumes-from Container1 ubuntu
進入容器一中查看數據
# docker start -ai Container1
容器三,掛在只讀卷
# docker run -ti --name=Container3 --volumes-from Container2:ro ubuntu
刪除上面三個測試容易和卷
# docker rm Container1 Container2 Container3 # docker volume rm DataVolume1
# docker run -it --name mycentos1 -v /www:/tmp/test docker.io/centos:7 /bin/bash # docker run -d -v ~/logs:/var/log/nginx -p 80:80 -i nginx