Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows run docker with --network=host and access with 127.0.0.1

I have windows 10 pro and I'm trying to run a docker with network mode host.

my issue is that I can't run a docker and access it using the host ip not 127.0.0.1 and not the ip (in linux it works differently).

looks like the hyper v has it's own network that not accessible using the host ip

docker run -d --network=host nginx

output:

CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS                          PORTS               NAMES
8edd86bf292b        nginx                                             "nginx -g 'daemon of…"   3 seconds ago       Up 2 seconds                                        happy_curie

so there is no ports as expected but and no errors. When I'm trying to open the browser using 127.0.0.1 I'm getting ERR_CONNECTION_REFUSED if I set ports to instead of network mode host it is working

docker run -d -p 80:80   nginx

Hyper v Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . 

Remarks:

  • changing in the hyper v virtual switch manager the network to be external - not helping
    • firewall is disabled

any idea how to work with network mode host in windows?

like image 281
dsaydon Avatar asked Feb 21 '18 21:02

dsaydon


People also ask

How do I access Docker network host?

Accessing the Host With the Default Bridge Mode You just need to reference it by its Docker network IP, instead of localhost or 127.0. 0.1 . Your host's Docker IP will be shown on the inet line. Connect to this IP address from within your containers to successfully access the services running on your host.

How do I connect to a Docker container from outside the host on the same network window?

When you connect an existing container to a different network using docker network connect , you can use the --ip or --ip6 flags on that command to specify the container's IP address on the additional network. In the same way, a container's hostname defaults to be the container's ID in Docker.

What IP is 172.17 0.1 Docker?

The bridge connection docker0 – with IP address 172.17. 0.1 – is created by Docker at installation time. Because the host and all containers are connected to that network, our application only needs to listen to it.


1 Answers

Unfortunately host networking is not available for Docker for Windows and neither is macvlan networking. If you are not stuck on Hyper-V, consider using Docker Toolbox on Windows.

Quoted from: https://docs.docker.com/network/network-tutorial-host/#prerequisites

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.

Also see the following related issues on GitHub:

  1. https://github.com/docker/for-win/issues/1644
  2. https://github.com/docker/for-win/issues/937
  3. https://github.com/docker/for-win/issues/543
  4. https://github.com/docker/for-mac/issues/2716
like image 135
W1M0R Avatar answered Sep 27 '22 01:09

W1M0R