1、停止 Nginx 容器
docker stop nginx
2、查看 Nginx 容器 Id
docker inspect nginx | grep "Id"
# 返回
"Id": "b5ec8ed792bfb2392b6f42ca32f8d7791e57f7b961bfca1c82cf7014ac36cf16",
3、修改
vim /var/lib/docker/containers/b5ec8ed792bfb2392b6f42ca32f8d7791e57f7b961bfca1c82cf7014ac36cf16/hostconfig.json
# 80是容器端口,8080是本地端口,可修改成 8081端口
"PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"8080"}]}
# 查看
vim /var/lib/docker/containers/b5ec8ed792bfb2392b6f42ca32f8d7791e57f7b961bfca1c82cf7014ac36cf16/config.v2.json
# 容器内部端口
"ExposedPorts":{"80/tcp":{}}
# 这1处,是动态生成的,如果 nginx 容器关闭,这里会显示 null ,启动后,才会显示。
"Ports":{"80/tcp":[{"HostIp":"0.0.0.0","HostPort":"8080"}]}
4、重启
systemctl restart docker