共计 1380 个字符,预计需要花费 4 分钟才能阅读完成。
容器数据卷
指定门路挂载
-v 宿主机目录: 容器目录
docker run -it -v 宿主机目录: 容器目录 centos /bin/bash
#查看挂载信息
docker inspect 容器 ID
"Mounts": [
{
"Type": "bind",
"Source": "宿主机目录",
"Destination": "容器目录",
...
}
]
匿名挂载
-v 容器目录
docker run -d -P --name test1 -v /test nginx
-P 随机凋谢端口
#查看所有 volume 信息
docker volume ls
DRIVER VOLUME NAME
local ccae06dda8374c37d25321b266e1d77eb786594f1aa9dfb861eb6097114d78da
#查看具体挂载
docker volume inspect ccae06dda8374c37d25321b266e1d77eb786594f1aa9dfb861eb6097114d78da
[
{
"CreatedAt": "2021-08-01T20:09:40+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/ccae06dda8374c37d25321b266e1d77eb786594f1aa9dfb861eb6097114d78da/_data",
"Name": "ccae06dda8374c37d25321b266e1d77eb786594f1aa9dfb861eb6097114d78da",
"Options": null,
"Scope": "local"
}
]
具名挂载
具名挂载能够不便的找到咱们的卷,应用较多
-v 卷名: 容器目录
docker run -d -P --name test2 -v test-name:/test nginx
#查看所有 volume 信息
docker volume ls
DRIVER VOLUME NAME
local test-name
#查看具体挂载
docker volume inspect test-name
[
{
"CreatedAt": "2021-08-01T20:12:29+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/test-name/_data",
"Name": "test-name",
"Options": null,
"Scope": "local"
}
]
docker 默认挂载目录:/var/lib/docker/volumes/...
拓展
-v 通过容器内门路:ro/rw 扭转读写权限
ro readonly #只读(容器内无奈批改,只能通过宿主机操作)rw readwrite #可读可写(默认)
Mysql 数据挂载
官网文档:https://hub.docker.com/_/mysql
# 获取镜像
docker pull mysql:5.7
#数据挂载
docker run -d -p 3310:3306 \
-v /home/mysql/conf:/etc/mysql/conf.d \
-v /home/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD= 明码 \
--name 容器名称 \
mysql:5.7
测试连贯
正文完