docker 具名挂载

2023-12-13 04:25:02

具名挂载

[root@qingfeng home]# docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx nginx
706c9abfa46c4f39f5d61be03601092e52b36fcc61e4efa8d443c798aa5362d4
[root@qingfeng home]# docker volume ls
DRIVER    VOLUME NAME
local     2bd1893a934b0688a7bd808812307e387468fd22a9a338beb04f9ec6551d613c
local     6c8b8fac6ccece338aa8b39331868b02c897be4dd61e1fe31b0c6db740107bdc
local     8af8fc81cee349276a42341ba0ad8af9c701d6511393fb92d42dac82b9e97164
local     09cc9df7e999dafca51c362c5803ee9d0a753f4c3cf913896544e9f8364c6cde
local     57a69e1dc3e90009ada41bcf5d051824c5bb436fae5a60c148252445eef42207
local     ce6d1a62e54b6195f648421f610dffe4eb7136e8aaf8c721552407198a22a43a
local     f56c053639abb5c56a96011e8e825f330052af2126cf67edbddbf548541bca84
local     home_db
local     home_wordpress
local     juming-nginx		//这个是指定名字
local     mysql

# 检查,查看挂载位置
[root@qingfeng home]# docker volume inspect juming-nginx
[
    {
        "CreatedAt": "2023-12-02T20:20:57+08:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/juming-nginx/_data",		//这里就是具体的挂载位置
        "Name": "juming-nginx",
        "Options": null,
        "Scope": "local"
    }
]

所有的docker容器内的卷,没有指定目录的情况下都是在/var/lib/docker/volumes/卷名/_data数据

[root@qingfeng home]# cd /var/lib/docker/	#docker所有的文件都在这个目录下
[root@qingfeng docker]# ls
buildkit    engine-id  network   plugins   swarm  volumes
containers  image      overlay2  runtimes  tmp
[root@qingfeng docker]# cd volumes/
[root@qingfeng volumes]# ls
09cc9df7e999dafca51c362c5803ee9d0a753f4c3cf913896544e9f8364c6cde
2bd1893a934b0688a7bd808812307e387468fd22a9a338beb04f9ec6551d613c
57a69e1dc3e90009ada41bcf5d051824c5bb436fae5a60c148252445eef42207
6c8b8fac6ccece338aa8b39331868b02c897be4dd61e1fe31b0c6db740107bdc
8af8fc81cee349276a42341ba0ad8af9c701d6511393fb92d42dac82b9e97164
backingFsBlockDev
ce6d1a62e54b6195f648421f610dffe4eb7136e8aaf8c721552407198a22a43a
f56c053639abb5c56a96011e8e825f330052af2126cf67edbddbf548541bca84
home_db
home_wordpress
juming-nginx
metadata.db
mysql
[root@qingfeng volumes]# cd juming-nginx/
[root@qingfeng juming-nginx]# ls
_data
[root@qingfeng juming-nginx]# cd _data/
[root@qingfeng _data]# ls
conf.d          mime.types  nginx.conf   uwsgi_params
fastcgi_params  modules     scgi_params

我们通过具名挂载可以方便的找到我们的一个卷,大多数情况在使用的具名挂载

# 如何分辨是具名挂载,还是指定匿名挂载,还是指定路径挂载
-v	容器内部路径		//匿名挂载
-v	卷名:容器内路径	//具名挂载
-v	/宿主机路径:容器内路径	//指定路径挂载,前面都是/开头的

文章来源:https://blog.csdn.net/xubaodong_1/article/details/134817088
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。