每个容器都有自己json配置文件,存放路径为宿主主机的 /var/lib/docker/containers/container-ID/config.v2.json
1.停止docker服务(必须)
systemctl stop docker.service
2.修改配置文件
vim /var/lib/docker/containers/container-ID/config.v2.json
3.config.v2.json配置文件(默认不可见)省略部分节点
{
"StreamConfig": {},
"State": { },
"ID": "acfe1b302c7849ae5031bafd362a2415da1df0c97d7025b614b8c8446147ff7f",
"Created": "2021-09-06T02:02:31.1771842Z",
"Managed": false,
"Path": "/docker-entrypoint.sh",
"Args": [... ],
"Config": {},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [...],
"Image": "822b7e",
"Volumes": null,
"WorkingDir": "",
"OnBuild": null,
"StopSignal": "SIGQUIT"
},
"Image": "sha256:822b7ec2aaf2122b8f80f9c7f45ca62ea3379bf33af4e042b67aafbf6eac1941",
"NetworkSettings": {... },
"LogPath": ...
"Name": "/yto-nginx",
"Driver": "overlay2",
"OS": "linux",
"MountLabel": "",
"ProcessLabel": "",
"RestartCount": 0,
"HasBeenStartedBefore": true,
"HasBeenManuallyStopped": true,
"MountPoints": { #挂载配置},
"SecretReferences": null,
"ConfigReferences": null,
"AppArmorProfile": "",
"HostnamePath": "/var/lib/docker/containers/acfe1b302c7849ae5031bafd362a2415da1df0c97d7025b614b8c8446147ff7f/hostname",
"HostsPath": "/var/lib/docker/containers/acfe1b302c7849ae5031bafd362a2415da1df0c97d7025b614b8c8446147ff7f/hosts",
"ShmPath": "",
"ResolvConfPath": "/var/lib/docker/containers/acfe1b302c7849ae5031bafd362a2415da1df0c97d7025b614b8c8446147ff7f/resolv.conf",
"SeccompProfile": "",
"NoNewPrivileges": false,
"LocalLogCacheMeta": {
"HaveNotifyEnabled": false
}
}
4.config.v2.json配置文件找到MountPoints节点
节点含义:
-v /mnt/nginx/nginx.conf:/etc/nginx/nginx.conf
-v /mnt/nginx/logs:/var/log/nginx
-v /mnt/nginx/html:/usr/share/nginx/html
-v /mnt/nginx/conf:/etc/nginx/conf.d
--privileged=true
-#使用该参数,container内的root拥有真正的root权限。
-#否则,container内的root只是外部的一个普通用户权限。
-#privileged启动的容器,可以看到很多host上的设备,并且可以执行mount。
-#甚至允许你在docker容器中启动docker容器。
{
"MountPoints": {
"/etc/nginx/conf.d": {
"Source": "/mnt/nginx/conf",
"Destination": "/etc/nginx/conf.d",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/mnt/nginx/conf",
"Target": "/etc/nginx/conf.d"
},
"SkipMountpointCreation": false
},
"/etc/nginx/nginx.conf": {
"Source": "/mnt/nginx/nginx.conf",
"Destination": "/etc/nginx/nginx.conf",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/mnt/nginx/nginx.conf",
"Target": "/etc/nginx/nginx.conf"
},
"SkipMountpointCreation": false
},
"/usr/share/nginx/html": {
"Source": "/mnt/nginx/html",
"Destination": "/usr/share/nginx/html",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/mnt/nginx/html",
"Target": "/usr/share/nginx/html"
},
"SkipMountpointCreation": false
},
"/var/log/nginx": {
"Source": "/mnt/nginx/logs",
"Destination": "/var/log/nginx",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/mnt/nginx/logs",
"Target": "/var/log/nginx"
},
"SkipMountpointCreation": false
}
}
}
网友评论