当 docker run 命令中提到 --net=host 时,Docker 容器不会公开端口 [英] Docker container doesn't expose ports when --net=host is mentioned in the docker run command

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

问题描述

我在 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.docker 版本为 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屋!

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