[英]docker not exposing the port with network host
I am trying to run a docker container listening on port 5555, the image is built with EXPOSE 5555
in Dockerfile and I am running the container as below我正在尝试运行一个侦听端口 5555 的
EXPOSE 5555
容器,图像是使用EXPOSE 5555
构建的,我正在运行容器,如下所示
$ docker run -d --name controler -p 5555:5555 -v /var/run/docker.sock:/var/run/docker.sock --net=host my_image:latest
The container starts fine but the ports are not exposed, running docker port returns an error message容器启动正常但端口没有暴露,运行 docker port 返回错误消息
$ docker port controler 5555
Error: No public port '5555/tcp' published for controler
If I run the container without --net=host
, the ports are exposed and I can access the container.如果我在没有
--net=host
情况下运行容器,则会暴露端口并且我可以访问该容器。
Any idea or hints on what is really happening here is appreciated.对这里真正发生的事情的任何想法或提示表示赞赏。
Note: I am using the latest docker for mac beta Version 1.12.0-beta21 (build: 11019) on my mac running el capitan
注意:我在运行 el capan 的 mac 上使用最新的 docker for mac beta 版本 1.12.0-beta21(版本:11019)
--net=host
option --net=host
选项This option bind the virtual NIC of the container to the host physical NIC (by giving full access to local system services such as D-bus).此选项将容器的虚拟 NIC 绑定到主机物理 NIC(通过授予对本地系统服务(例如 D-bus)的完全访问权限)。
When this option is used every program that request a network socket will be granted one by the host from the physical NIC.使用此选项时,主机将从物理 NIC 授予一个请求网络套接字的程序。 Your service will then be using the
5555
port as expected.然后,您的服务将按预期使用
5555
端口。
-p 5555:5555
option -p 5555:5555
选项This option bind (through iptable
-like mechanism) the network socket containter-ip:5555
to the network socket host-ip:5555
.此选项将(通过
iptable
类的机制)网络套接字containter-ip:5555
绑定到网络套接字host-ip:5555
。
It seems, IMHO, a bit illogical to use them both.恕我直言,同时使用它们似乎有点不合逻辑。 If the needs is to publish the containerized service to the socket
host-ip:5555
then the cleanest way is to only use the -p 5555:5555
option.如果需要将容器化服务发布到套接字
host-ip:5555
那么最干净的方法是仅使用-p 5555:5555
选项。
`add your ip in jdbc url spring.datasource.url=jdbc:postgresql://12.45.67.12:5432/postgres `在 jdbc url spring.datasource.url=jdbc:postgresql://12.45.67.12:5432/postgres 中添加你的 ip
add this conf in pg_hba.conf file host all all 0.0.0.0/0 md5`在 pg_hba.conf 文件中添加这个 conf 主机所有 0.0.0.0/0 md5`
this conf is working for me这个 conf 对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.