Docker更改在活动集装箱上发布的端口 [英] Docker change published ports on live container

查看:127
本文介绍了Docker更改在活动集装箱上发布的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在活动集装箱上更改发布的端口,例如

I'd like to change the published ports on a live container for example

docker run -p 80:80 --name nginx_live nginx

然后再更改为另一个端口,例如 -p 8080:80

And then later on, change that to another port, example -p 8080:80

推荐答案

Docker没有机制更改已发布的端口一旦它已经开始的容器。当您发布端口时,会发生两件事:

Docker does not have a mechanism for changing the published ports of a container once it has started. When you publish a port, two things happen:


  • Docker创建 iptables 将流量重定向到公共端口到容器的 nat 表。

  • Docker启动代理服务侦听该端口处理本地生成的流量。

  • Docker creates iptables rules in the nat table that redirect traffic to the "public" port to the container.
  • Docker starts a proxy service listening on that port to handle locally generated traffic.

虽然您可以在理论上手动更新防火墙规则,使服务在新端口可用,无法解除Docker代理的绑定,因此无法使用该public端口启动任何新服务。

While you could in theory manually update the firewall rules to make the service available at a new port, you would not be able to unbind the Docker proxy and would thus be unable to start any new services using that "public" port.

您最佳的操作方法只是删除容器并重新部署它,或依靠某种前端代理来处理重定向,而不是使用Docker的端口发布机制。

Your best course of action is simply to delete the container and redeploy it, or rely on some sort of front-end proxy to handle the redirect rather than using Docker's port publishing mechanism.

这篇关于Docker更改在活动集装箱上发布的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆