docker 容器卷
创建各种卷
[root@docker ~]# docker volume create mqy-vo101
mqy-vo101
[root@docker ~]# docker inspect mqy-vo101
[
{
"CreatedAt": "2022-04-27T16:12:45+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/mqy-vo101/_data",
"Name": "mqy-vo101",
"Options": {},
"Scope": "local"
}
]
[root@docker ~]# docker volume create --driver local \
--opt type=tmpfs
--opt device=tmpfs
--opt o=size=100m,uid=1000
mqy-vo
mqy-vo
[root@docker ~]# docker inspect mqy-vo
[
{
"CreatedAt": "2022-04-27T16:14:18+08:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/mqy-vo/_data",
"Name": "mqy-vo",
"Options": {
"device": "tmpfs",
"o": "size=100m,uid=1000",
"type": "tmpfs"
},
"Scope": "local"
}
]
[root@docker ~]# docker volume create --label city=wuhan mqy-vo3
mqy-vo3
[root@docker ~]# docker inspect mqy-vo3
[
{
"CreatedAt": "2022-04-27T16:14:56+08:00",
"Driver": "local",
"Labels": {
"city": "wuhan"
},
"Mountpoint": "/var/lib/docker/volumes/mqy-vo3/_data",
"Name": "mqy-vo3",
"Options": {},
"Scope": "local"
}
]
显示卷
[root@docker ~]# docker volume ls
没有被使用的卷
[root@localhost volumes]# docker volume ls -f dangling=true
驱动为local的卷
[root@localhost volumes]# docker volume ls -f driver=local
根据label元数据筛选
[root@localhost volumes]# docker volume ls --filter label=city
根据名称筛选
[root@localhost volumes]# docker volume ls -f name=03
只打印卷名
[root@localhost volumes]# docker volume ls -q
内容过滤输出
[root@localhost volumes]# docker volume ls --format "{{.Name}}: {{.Driver}}"
[root@localhost volumes]# docker volume ls --format "{{.Name}}: {{.Mountpoint}}: {{.Labels}}"
查看卷详情
[root@docker ~]# docker volume inspect --help
Usage: docker volume inspect [OPTIONS] VOLUME [VOLUME...]
Display detailed information on one or more volumes
Options:
-f, --format string Format the output using the given Go template
[root@docker ~]#
创建一个卷并查看信息
[root@docker ~]# docker volume create --driver local \
--opt type=tmpfs
--opt device=tmpfs
--opt o=size=100m,uid=1000
--label city=wuhan
--label type=tmpfs
test-vo1
test-vo1
[root@docker ~]# docker volume inspect test-vo1
[
{
"CreatedAt": "2022-04-27T16:42:21+08:00",
"Driver": "local",
"Labels": {
"city": "wuhan",
"type": "tmpfs"
},
"Mountpoint": "/var/lib/docker/volumes/test-vo1/_data",
"Name": "test-vo1",
"Options": {
"device": "tmpfs",
"o": "size=100m,uid=1000",
"type": "tmpfs"
},
"Scope": "local"
}
]
[root@docker ~]#
找到这个卷并查看挂载点
[root@docker ~]# docker volume inspect --format '{{ .Mountpoint}}' test-vo1
/var/lib/docker/volumes/test-vo1/_data
找到这个卷的元数据
[root@docker ~]# docker volume inspect --format '{{ .Options }}' test-vo1
map[device:tmpfs o:size=100m,uid=1000 type:tmpfs]
简略元数据
[root@hqs ~]# docker volume inspect --format '{{ .Options.o }}' test-vol
size=100m,uid=1000
元数据地址
[root@hqs ~]# docker volume inspect --format '{{ .Labels.city }}' test-vol
wuhan