docker run -d -p 3310:3306 -v /home/nginx:/etc/nginx nginx
#指定主机和容器的挂载目录,但是没有挂载名,是指定路径挂载,匿名挂载的一种,因为其生成的卷名也是匿名的
docker run -d -p 3310:3306 -v /etc/nginx nginx
#只指定了容器目录,没有指定主机目录
以上方式都是匿名的挂载,创造的是匿名卷
2. 查看主机所有的volume(卷)
cd /var/lib/docker/volumes
或者
docker volume ls
二者效果一样
[root@QK ~]# cd /[root@QK /]# ls
bin dev home lib64 media myredis proc run srv tmp var
boot etc lib lost+found mnt opt root sbin sys usr
[root@QK /]# cd var[root@QK var]# ls
adm crash empty gopher lib lock mail opt run tmp
cache db games kerberos local log nis preserve spool yp
[root@QK var]# cd lib[root@QK lib]# ls
alternatives cloud dhclient initramfs misc plymouth rpm selinux tuned
authconfig containerd docker logrotate NetworkManager polkit-1 rpm-state stateless yum
chrony dbus games machines os-prober postfix rsyslog systemd
[root@QK lib]# cd docker/[root@QK docker]# ls
buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes
[root@QK docker]# cd volumes[root@QK volumes]# ls
15515c0869ba1c3ebf5d829fe6d56a121686525146feed971df4e13ab674d426
33db408050d1f1b75fdba438ea1b07bcf32e9032689ca645609c35f8a5a1806b
34be1ad443ec44b6d8b1f30cb3b36912e241214c3e52e38fd94a8bb64a5544a2
7037f9c4c2821740a6bd533abe67d8e694f2850d5904fb591a309dd849a55ec8
backingFsBlockDev
d81a818534400ec7711f81f61bbe62845f704888736d7a0efff7fd9aa6f70b40
ffd93cf930db42a999011174c0444cc2ed8be7bea88e3fc9c4207fca63bc1fae
metadata.db
[root@QK volumes]# cd /[root@QK /]# docker volume ls
DRIVER VOLUME NAME
local 33db408050d1f1b75fdba438ea1b07bcf32e9032689ca645609c35f8a5a1806b
local 34be1ad443ec44b6d8b1f30cb3b36912e241214c3e52e38fd94a8bb64a5544a2
local 7037f9c4c2821740a6bd533abe67d8e694f2850d5904fb591a309dd849a55ec8
local 15515c0869ba1c3ebf5d829fe6d56a121686525146feed971df4e13ab674d426
local d81a818534400ec7711f81f61bbe62845f704888736d7a0efff7fd9aa6f70b40
local ffd93cf930db42a999011174c0444cc2ed8be7bea88e3fc9c4207fca63bc1fae
[root@QK /]#
3. 具名挂载
不指定主机地址
主机名不使用 “ / ” ,否则就会变成绝对地址
docker run -d -p 3310:3306 -v myclearnginx:/etc/nginx nginx
和匿名挂载的区别(volume name 是自定义的,不是随机生成的)
[root@QK /]# docker run -d -P --name nginx02 -v mynginx:/etc/nginx nginx
1kl1827dhic88cjc89x9d8d56a121686525146feed971df4e13ab674d426
[root@QK /]# docker volume ls
DRIVER VOLUME NAME
local 33db408050d1f1b75fdba438ea1b07bcf32e9032689ca645609c35f8a5a1806b
local 34be1ad443ec44b6d8b1f30cb3b36912e241214c3e52e38fd94a8bb64a5544a2
local 7037f9c4c2821740a6bd533abe67d8e694f2850d5904fb591a309dd849a55ec8
local 15515c0869ba1c3ebf5d829fe6d56a121686525146feed971df4e13ab674d426
local d81a818534400ec7711f81f61bbe62845f704888736d7a0efff7fd9aa6f70b40
local ffd93cf930db42a999011174c0444cc2ed8be7bea88e3fc9c4207fca63bc1fae
local mynginx
[root@QK /]#