Docker container doesn't expose ports when --net=host is mentioned in the docker run command

独自空忆成欢 提交于 2019-11-29 05:27:41

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.

I was confused by this answer. Apparently my docker image should be reachable on port 8080. But it wasn't. Then I read

https://docs.docker.com/network/host/

To quote

The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.

That's rather annoying as I'm on a Mac. The docker command should report an error rather than let me think it was meant to work.

Discussion on why it does not report an error

https://github.com/docker/for-mac/issues/2716

Not sure I'm convinced.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!