docker追加端口映射目录映射

1.获取容器id

使用docker ps亦可,这里为了方便说明获取完整id

SHELL
docker inspect 容器名 | grep "\"Id\":\s\""
点击展开查看更多
SHELL
$ docker inspect apache | grep "\"Id\":\s\""
(输出)"Id": "31usfxtbv37m97qyu3uqa1nkowvw6bdwu423x1qvf53oic3pd7l71ivqskni3bww",
点击展开查看更多

2.寻找配置文件

PLAINTEXT
/var/lib/docker/containers/容器id/
点击展开查看更多
SHELL
$ cd /var/lib/docker/containers/31usfxtbv37m97qyu3uqa1nkowvw6bdwu423x1qvf53oic3pd7l71ivqskni3bww/
点击展开查看更多

3.修改配置文件

目录映射

hostconfig.json 文件

位置:文件开头,关键字:Binds

JSON
"Binds":["/root/apche:/var/www/html","/root/tmp:/etc/apache2/sites-enabled"]
点击展开查看更多

格式化后:其实内容跟run时的-v参数一样,直接修改即可

JSON
"Binds": [
    "/root/apche:/var/www/html",
    "/root/tmp:/etc/apache2/sites-enabled"
]
点击展开查看更多

模式:

JSON
"Binds": [
    "外部目录:容器内目录"
    ......
]
点击展开查看更多

config.v2.json 文件

位置:靠后,关键字:MountPoints

JSON
"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}}
点击展开查看更多

解析后:

JSON
"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
    }
}
点击展开查看更多

模式:

JSON
"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

版权声明

作者: Chaim

链接: https://chaim.eu.org/posts/docker%E8%BF%BD%E5%8A%A0%E7%AB%AF%E5%8F%A3%E6%98%A0%E5%B0%84%E5%92%8C%E7%9B%AE%E5%BD%95%E6%98%A0%E5%B0%84/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键