修改Docker容器端口

1、停止容器

docker stop 容器ID

2、停止docker

systemctl stop docker

3、修改文件

先进入目录

cd /var/lib/docker/containers/容器ID*
(1)修改hostconfig.json文件
vi hostconfig.json

找到类似如下字段:

"PortBindings": {
    "111/tcp": [  //容器端口1
        {
            "HostIp": "",
            "HostPort": "111" //宿柱机端口1
        }
    ],
    "222/tcp": [   //容器端口2
        {
            "HostIp": "",
            "HostPort": "222" //宿柱机端口2
        }
    ]
}

​ 按照json文件格式添加或修改成需要的端口号即可

(2)修改config.v2.json文件

​ 修改两处:

①、一处为:
"ExposedPorts": {
    "111/tcp": {},
    "222/tcp": {}
}
②、另一处为:
"Ports": {
    "111/tcp": [
        {
            "HostIp": "0.0.0.0",
            "HostPort": "111"
        },
        {
            "HostIp": "::",
            "HostPort": "111"
        }
    ],
    "222/tcp": [
        {
            "HostIp": "0.0.0.0",
            "HostPort": "222"
        },
        {
            "HostIp": "::",
            "HostPort": "222"
        }
    ]
}

和修改hostconfig.json文件类似,符合json语法格式即可

4、重启docker

systemctl restart docker

5、重启容器

docker restart 容器ID

你可能感兴趣的:(工具,docker,容器,运维)