docker追加端口映射和目录映射
1.获取容器id
使用
docker ps亦可,这里为了方便说明获取完整id
- 命令
docker inspect 容器名 | grep "\"Id\":\s\""- 实例
$ docker inspect apache | grep "\"Id\":\s\""
(输出)"Id": "31usfxtbv37m97qyu3uqa1nkowvw6bdwu423x1qvf53oic3pd7l71ivqskni3bww",2.寻找配置文件
- 配置文件路径
/var/lib/docker/containers/容器id/
- 实例
$ cd /var/lib/docker/containers/31usfxtbv37m97qyu3uqa1nkowvw6bdwu423x1qvf53oic3pd7l71ivqskni3bww/3.修改配置文件
目录映射
hostconfig.json 文件
位置:文件开头,关键字:Binds
"Binds":["/root/apche:/var/www/html","/root/tmp:/etc/apache2/sites-enabled"]格式化后:其实内容跟run时的-v参数一样,直接修改即可
"Binds": [
"/root/apche:/var/www/html",
"/root/tmp:/etc/apache2/sites-enabled"
]模式:
"Binds": [
"外部目录:容器内目录"
......
]config.v2.json 文件
位置:靠后,关键字:MountPoints
"MountPoints":{"/etc/apache2/sites-enabled":{"Source":"/root/tmp","Destination":"/etc/apache2/sites-enabled","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/root/tmp","Target":"/etc/apache2/sites-enabled"},"SkipMountpointCreation":false},"/var/www/html":{"Source":"/root/apache","Destination":"/var/www/html","RW":true,"Name":"","Driver":"","Type":"bind","Propagation":"rprivate","Spec":{"Type":"bind","Source":"/root/apache","Target":"/var/www/html"},"SkipMountpointCreation":false}}解析后:
"MountPoints": {
"/etc/apache2/sites-enabled": {
"Source": "/root/tmp",
"Destination": "/etc/apache2/sites-enabled",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/root/tmp",
"Target": "/etc/apache2/sites-enabled"
},
"SkipMountpointCreation": false
},
"/var/www/html": {
"Source": "/root/apache",
"Destination": "/var/www/html",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "/root/apache",
"Target": "/var/www/html"
},
"SkipMountpointCreation": false
}
}模式:
"MountPoints": {
"容器内目录": {
"Source": "容器外目录",
"Destination": "容器内目录",
"RW": true,
"Name": "",
"Driver": "",
"Type": "bind",
"Propagation": "rprivate",
"Spec": {
"Type": "bind",
"Source": "容器外目录",
"Target": "容器内目录"
},
"SkipMountpointCreation": false
}
......
......
}端口映射
hostconfig.json 文件
位置:文件开头,关键字:Binds
config.v2.json 文件
位置:靠后,关键字:MountPoints