在docker运行命令中提到了--net = host时,Docker容器不会暴露端口 [英] Docker container doesn't expose ports when --net=host is mentioned in the docker run command

查看:1409
本文介绍了在docker运行命令中提到了--net = host时,Docker容器不会暴露端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CentOS Docker主机上有一个CentOS Docker容器。当我使用这个命令来运行docker的图像 docker run -d --net = host -p 8777:8777 ceilometer:1.x docker容器获取主机的IP,但没有没有分配端口。



如果我运行相同的命令没有--net = host docker run -d -p 8777 :8777 ceilometer:1.x docker公开端口,但使用不同的IP。码头版本是1.10.1。我希望docker容器具有与主机端口相同的IP。我也在 Dockerfile 中指出了 EXPOSE 8777 ,但是当--net = host是

解决方案


docker版本是1.10.1。我希望docker容器与暴露端口的主机具有相同的IP。


当您使用 net = host 它告诉容器使用主机网络堆栈。因此,您不能将端口暴露给主机,因为它主机(就网络堆栈而言)。



docker inspect 可能不会显示公开端口,但是如果您有一个应用程序在端口上侦听,它将可用,就好像它在主持人。


I have a CentOS docker container on a CentOS docker host. When I use this command to run the docker image docker run -d --net=host -p 8777:8777 ceilometer:1.x the docker container get host's IP but doesn't have ports assigned to it.

If I run the same command without "--net=host" docker run -d -p 8777:8777 ceilometer:1.x docker exposes the ports but with a different IP. The docker version is 1.10.1. I want the docker container to have the same IP as the host with ports exposed. I also have mentioned in the Dockerfile the instruction EXPOSE 8777 but with no use when "--net=host" is mentioned in the docker run command.

解决方案

The docker version is 1.10.1. I want the docker container to have same ip as the host with ports exposed.

When you use --net=host it tells the container to use the hosts networking stack. So you can't expose ports to the host, because it is the host (as far as the network stack is concerned).

docker inspect might not show the expose ports, but if you have an application listening on a port, it will be available as if it were running on the host.

这篇关于在docker运行命令中提到了--net = host时,Docker容器不会暴露端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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