如何将静态端口分配给容器? [英] How to assign as static port to a container?

查看:213
本文介绍了如何将静态端口分配给容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我要分配一个容器一个端口,以便每次重新启动容器后都会获得相同的端口。容器,其中有一个Apache。 Apache在容器内的80端口上运行。
现在,启动容器后,docker将主机端口分配到容器端口,例如:49154 - > 80.但主机端口在重新启动后更改,具体取决于运行的容器数。我试图在容器的config.json文件中指定端口,但是会被覆盖。



是否可以手动指定主机端口?



感谢提前和最好的问候,
Chris

解决方案

docker.io文档: https://docs.docker.com/engine/userguide / networking / default_network / dockerlinks /

  $ sudo docker run -p 80:80< image> < CMD> 

默认端口重定向可以内置到EXPOSE build命令的容器中。


I want to assign a container a port, so that it gets the same port after every restart of the container.

Example: I have a container, which has an Apache in it. The Apache runs on port 80 inside the container. Now, after starting the container, docker assigns a host port to the container port, for example: 49154 -> 80. But the host port changes after restart, depending on the number of running containers. I tried to specify the port in the config.json file of the container, but it gets overwritten.

Is it possible to specify the host port manually?

Thanks in advance and best regards, Chris

解决方案

Per the docker.io documentation: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

$ sudo docker run -p 80:80 <image> <cmd>

Default port redirects can be built into a container with the EXPOSE build command.

这篇关于如何将静态端口分配给容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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