docker run -it -v 本机目录:容器目录 镜像id
实战安装mysql
docker pull mysql:5.7
docker run -d -p 3308:3306 -v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --name mysql01 mysql:5.7
docker volume ls #查看所有卷的情况
具名挂载和匿名挂载
具名挂载
[root@localhost ~]# docker run -d -P -v juming:/etc/nginx --name nginx02 nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
bf5952930446: Already exists
cb9a6de05e5a: Pull complete
9513ea0afb93: Pull complete
b49ea07d2e93: Pull complete
a5e4a503d449: Pull complete
Digest: sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661
Status: Downloaded newer image for nginx:latest
c59dd20aa38856d92f35e6f4ad17962c0827b588fe4029e118189ffb43a2a852
[root@localhost ~]# docker volume ls
DRIVER VOLUME NAME
local juming
[root@localhost ~]# docker volume inspect juming
[
{
"CreatedAt": "2020-08-26T00:40:59+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/juming/_data",
"Name": "juming",
"Options": null,
"Scope": "local"
}
]
:ro 只读,只能通过宿主机操作,不能通过容器
:rw可读可写,常用rw
容器和容器之间挂载
docker run -d -P -v juming:/etc/nginx --name nginx01 nginx
docker run -d -P --name nginx02 --volumes-from nginx01 nginx