如何在docker中创建volume?
在docker中,通过如下的命令创建volume:
# my_volume_01是自定义的volume的名字
docker volume create my_volume_01
查看创建的volume
docker volume ls
输出结果:
[root@centos7 ~]# docker volume ls DRIVER VOLUME NAME local my_volume_01 [root@centos7 ~]#
那么,这个volume具体在docker宿主机上的什么目录中?
docker volume inspect my_volume_01
[root@centos7 ~]# docker volume inspect my_volume_01 [ { "CreatedAt": "2022-08-23T04:41:24-04:00", "Driver": "local", "Labels": {}, "Mountpoint": "/var/lib/docker/volumes/my_volume_01/_data", "Name": "my_volume_01", "Options": {}, "Scope": "local" } ] [root@centos7 ~]#
"Mountpoint": "/var/lib/docker/volumes/my_volume_01/_data"
/var/lib/docker/volumes/my_volume_01/_data 就是这个volume在宿主机上的具体的目录位置。
[root@centos7 _data]# cd /var/lib/docker/volumes/my_volume_01/_data/ [root@centos7 _data]# ls -l total 0 [root@centos7 _data]#
该目录确实是在宿主机上存在的。
删除volume
docker volume rm my_volume_01
对应的目录也被删除了
[root@centos7 ~]# cd /var/lib/docker/volumes/my_volume_01/_data/ -bash: cd: /var/lib/docker/volumes/my_volume_01/_data/: No such file or directory [root@centos7 ~]#
OK,以上就是在docker上创建volume的过程!