当 docker run 命令中提到 --net=host 时,Docker 容器不公开端口 [英] Docker container doesn't expose ports when --net=host is mentioned in the docker run command
问题描述
我在 CentOS docker 主机上有一个 CentOS docker 容器.当我使用此命令运行 docker 映像 docker run -d --net=host -p 8777:8777 ceilometer:1.x
docker 容器获取主机的 IP 但没有分配端口它.
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.
如果我在没有--net=host"的情况下运行相同的命令 docker run -d -p 8777:8777 ceilometer:1.x
docker 会公开端口但使用不同的 IP.码头工人版本是 1.10.1.我希望 docker 容器具有与暴露端口的主机相同的 IP.我还在 Dockerfile
中提到了指令 EXPOSE 8777
但在 docker run
中提到--net=host"时没有用命令.
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.
推荐答案
docker 版本是 1.10.1.我希望 docker 容器与主机具有相同的 ip,并暴露端口.
The docker version is 1.10.1. I want the docker container to have same ip as the host with ports exposed.
当您使用 --net=host
时,它会告诉容器使用主机网络堆栈.因此,您不能向主机公开端口,因为它是主机(就网络堆栈而言).
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
可能不会显示暴露端口,但如果您有一个应用程序正在侦听某个端口,它将如同在主机上运行一样可用.
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 run 命令中提到 --net=host 时,Docker 容器不公开端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!