0

If I run docker container using the host network (--network host), for any services running in the container their exposed port can be directly accessed from host right?

I always thought so until I'm running docker container using the host network under Windows --

  • The ip a s eth0 shows that my container IP address is 192.168.65.3
  • The route | awk '/^default/ { print $2 }' gives 192.168.65.1
  • However, my host machine has an IP of 10.66.xx.xx

I.e., the container IP address and host IP are completely different. Unlike what the https://www.metricfire.com/blog/understanding-dockers-net-host-option/ says.

Anyway, if I'm running any services in the container, how to expose their port so that they can be directly accessed from host? (I thought with host network (--network host), you no longer need to map port from container to host)

thx

docker version Client: Docker Engine - Community Version: 19.03.8 API version: 1.40 Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:23:10 2020 OS/Arch: windows/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.8 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: afacb8b Built: Wed Mar 11 01:29:16 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: v1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683 

2 Answers 2

2

Host networking is not supported on Windows:

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

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

I would suggest trying the -p option to docker run, since that is supported on Windows.

Alternately, one forum user suggests using VirtualBox in bridged mode to install Linux, which can then use host networking. YMMV.

Sign up to request clarification or add additional context in comments.

1 Comment

1

Since version 4.34 Docker Desktop for Windows supports host networking. https://docs.docker.com/engine/network/drivers/host/

3 Comments

Would you give a link directly supporting such saying pls, as the link you provided clearly says that, "The host networking driver is supported on Docker Engine (Linux only) and Docker Desktop version 4.34 and later." and when I asked my OP, my Docker Engine was of Version 19.
@xpt There is Docker Desktop section on this page. Searh for these lines 'Host networking is supported on Docker Desktop version 4.34 and later. To enable this feature:'
In that case, I'm afraid it's your misunderstanding then, because if you look two paragraphs up from "Host networking is supported ...", you'll find what I've quoted above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.