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

2年前 (2022) 程序员胖胖胖虎阿
161 0 0

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

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
版权声明:程序员胖胖胖虎阿 发表于 2022年10月12日 上午10:16。
转载请注明:【Vegas原创】修改docker里面网站的port端口映射 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...