如何将端口映射分配给现有的Docker容器? [英] How do I assign a port mapping to an existing Docker container?
问题描述
我不知道我是否误解了这里的东西,但似乎只能通过从图像创建一个新的容器来设置端口映射。有没有办法将端口映射分配给现有的Docker容器?
我也对这个问题感兴趣。 / p>
如@Thasmo所述,端口转发只能使用'docker run'命令指定。
其他命令'docker start'没有 - p选项和'docker端口'仅显示当前转发。
要添加端口转发,我总是按照这些步骤,
-
停止运行容器
docker stop test01
-
提交容器
docker commit test01 test02
注意: strong>以上,
test02
是从test01
容器中构建的新图像。 / p> -
将运行从被提交的图像
docker run -p 8080:8080 -td test02
pre>
第一个8080是本地端口,第二个8080是容器端口。
I'm not sure if I've misunderstood something here, but it seems like it's only possible to set port mappings by creating a new container from an image. Is there a way to assign a port mapping to an existing Docker container?
I'm also interested in this problem.
As @Thasmo mentioned, port forwardings can be specified ONLY with 'docker run' command.
Other commands, 'docker start' does not have -p option and 'docker port' only displays current forwardings.
To add port forwardings, I always follow these steps,
stop running container
docker stop test01
commit the container
docker commit test01 test02
NOTE: The above,
test02
is a new image that I'm constructing from thetest01
container.re-run from the commited image
docker run -p 8080:8080 -td test02
Where the first 8080 is the local port and the second 8080 is the container port.
这篇关于如何将端口映射分配给现有的Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!