Docker修改容器挂载目录的三种方式
方式一:修改配置文件(需要停止docker服务)1、systemctl stop docker.service(关键,修改之前必须停止docker服务)2、修改宿主机文件:vim /var/lib/docker/containers/【container-ID】/config.v2.json【container-ID】=》需要修改容器相对于的ID值;修改配置文件中的目录位置,然后保存退出未缩进版:
·
方式一:修改配置文件(需要停止docker服务)
1、systemctl stop docker.service(关键,修改之前必须停止docker服务)
2、修改宿主机文件:vim /var/lib/docker/containers/【container-ID】/config.v2.json
【container-ID】=》需要修改容器相对于的ID值;
修改配置文件中的目录位置,然后保存退出
未缩进版:
"MountPoints":{"/home":{"Source":"/docker","Destination":"/home","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"//docker/","Target":"/home"}}}
缩进版:
"MountPoints":{"/home":{
"Source":"/docker",
"Destination":"/home",
"RW":true,
"Name":"",
"Driver":"",
"Type":"bind",
"Propagation":"rprivate",
"Spec":{"Type":"bind","Source":"//docker/","Target":"/home"}
}}
由于看了几篇文章还是觉得方法一的说明不太清楚,就自己做了个实例进行结构分析。
![(https://img-blog.csdnimg.cn/20210526192537372.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDExODg5NA==,size_16,color_FFFFFF,t_70#pic_center)
截图对应代码:
"MountPoints":{
"/etc/mysql":{
"Source":"/mydata/mysql/conf",
"Destination":"/etc/mysql",
"RW":true,
"Name":"",
"Driver":"",
"Type":"bind",
"Propagation":"rprivate",
"Spec":
{
"Type":"bind",
"Source":"/mydata/mysql/conf",
"Target":"/etc/mysql"
},
"SkipMountpointCreation":false
},
"/var/lib/mysql":{
"Source":"/mydata/mysql/data",
"Destination":"/var/lib/mysql",
"RW":true,
"Name":"",
"Driver":"",
"Type":"bind",
"Propagation":"rprivate",
"Spec":
{
"Type":"bind",
"Source":"/mydata/mysql/data",
"Target":"/var/lib/mysql"
},
"SkipMountpointCreation":false
},
"/var/log/mysql":{
"Source":"/mydata/mysql/log",
"Destination":"/var/log/mysql",
"RW":true,
"Name":"",
"Driver":"",
"Type":"bind",
"Propagation":"rprivate",
"Spec":
{
"Type":"bind",
"Source":"/mydata/mysql/log",
"Target":"/var/log/mysql"
},
"SkipMountpointCreation":false
}
},
docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/conf:/etc/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/log:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7
3、启动docker服务
systemctl start docker.service
4、启动docker容器
docker start <container-name/ID>
方式二、三要重新run容器并添加映射,引用一下别人的文章。
更多推荐
已为社区贡献1条内容
所有评论(0)