修改已运行的 Docker 容器端口映射?
1 | https://www.51cto.com/article/716102.html |
1. 查看 [CONTAINER ID]
1 | docker ps -a |
返回如下信息:
1 2 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0217c7c62521 ansible/centos7-ansible "/usr/sbin/init" 7 hours ago Up 48 minutes 0.0.0.0:8081->22/tcp, 0.0.0.0:8082->80/tcp, 0.0.0.0:8083->443/tcp, 0.0.0.0:8085->1080/tcp, 0.0.0.0:8084->5901/tcp centos72 |
2. 关闭 [CONTAINER ID]
1 | docker stop 0217c7c62521 |
3. 查看容器完整的 hash_of_the_container 数值
1 2 | docker inspect [CONTAINER ID] | grep Id docker inspect 0217c7c62521| grep Id |
返回如下信息:
1 | "Id": "0217c7c625219909a46fdc927f203fea4b6a618137d645657acd20c5f6446750", |
4. 修改 hostconfig.json 配置文件
1 2 | cd /var/lib/docker/containers/{hash_of_the_container}/ cd /var/lib/docker/containers/0217c7c625219909a46fdc927f203fea4b6a618137d645657acd20c5f6446750/ |
1 | vi hostconfig.json |
8082 –> 改成 80
8083 –> 改成 443
8083 –> 改成 443
5. 修改 config.v2.json 配置文件
1 | vi config.v2.json |
8082 –> 改成 80
8083 –> 改成 443
8083 –> 改成 443
我这台是不需要改
6. 重启docker.service
1 | systemctl restart docker.service |
7. 查看已经更新好了
1 2 3 | [root@iZj6c3t0cbgzdxy63zu6h4Z ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0217c7c62521 ansible/centos7-ansible "/usr/sbin/init" 7 hours ago Up 27 seconds 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8081->22/tcp, 0.0.0.0:8085->1080/tcp, 0.0.0.0:8084->5901/tcp centos72 |