【Amadeus原创】修改docker里面网站的port端口映射

切记:以下顺序千万不能颠倒!否则不生效!

1. 查看需要修改的容器,记住container id
docker ps -a
2. 停止容器
docker stop xxx
3. 修改容器的端口映射配置文件
vim /var/lib/docker/containers/{container_id}/hostconfig.json

"PortBindings": {
      "80/tcp": [
              {
              "HostIp": "",
              "HostPort": "8080"//宿主机ip
              }
          ]
      },
4. 重启docker服务
service docker restart
5.启动容器
docker start xxx

[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f6d2092f6ba requarks/wiki:latest "docker-entrypoint.s…" 2 weeks ago Up 3 seconds 3443/tcp, 0.0.0.0:8080->3000/tcp, :::8080->3000/tcp wiki
fdfc369cacfa mysql:latest "docker-entrypoint.s…" 2 weeks ago Up 5 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker stop wiki
wiki
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# vi hostconfig.json
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker start wiki
wiki
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker start mysql
mysql
[root@it 3f6d2092f6ba75ce3ad507f9d05a1def9fe6ccec216ffaa7d9417450e2db8f2d]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f6d2092f6ba requarks/wiki:latest "docker-entrypoint.s…" 2 weeks ago Up 8 seconds 3443/tcp, 0.0.0.0:80->3000/tcp, :::80->3000/tcp wiki
fdfc369cacfa mysql:latest "docker-entrypoint.s…" 2 weeks ago Up 2 seconds 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql

posted @ 2021-06-01 16:06  李济宏(Amadeus)  阅读(100)  评论(0编辑  收藏  举报