for-mac icon indicating copy to clipboard operation
for-mac copied to clipboard

net=host mode bug under mac, container with default bridge mode can not access host opening port

Open ziyouchutuwenwu opened this issue 10 years ago • 56 comments

Output of docker version:

(python2) mmcdeMacBook-Air:~ mmc$ docker version
Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:15:28 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 3
 Running: 2
 Paused: 0
 Stopped: 1
Images: 3
Server Version: 1.12.0
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 23
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: host null bridge overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.4.15-moby
Operating System: Alpine Linux v3.4
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.954 GiB
Name: moby
ID: D3CE:BLOM:7POQ:5KMA:LIMF:PSVT:MEAQ:GNEV:4JNX:N5YW:6HCJ:QD3X
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 26
 Goroutines: 40
 System Time: 2016-07-29T16:15:59.152792247Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8

Additional environment details (AWS, VirtualBox, physical, etc.):

virtualbox 5.1.2 r108956

here is my host mac network info local_network

issue 1 Steps to reproduce the issue:

  1. start a new container with -net=host mode
docker run -it --net=host edib/elixir-phoenix-dev /bin/bash
input ip address in container

Describe the results you received:

wish to see the same ip as host network interface eth0

Describe the results you expected:

host ip is 192.168.1.55, container ip is 192.168.65.xx, here is the screenshot

net_host

issue 2 Steps to reproduce the issue:

  1. start a new container with default mode
docker run -it edib/elixir-phoenix-dev /bin/bash

in container run 
telnet to 172.17.0.1 8888

Describe the results you received:

8888 is my host port, listening for http request, screenshot

web_page

container telnet 172.17.0.1 failed, but  ping 172.17.0.1 runs ok

default

Describe the results you expected:

running container can telnet to host port, it runs ok under linux docker.

ziyouchutuwenwu avatar Aug 02 '16 06:08 ziyouchutuwenwu

Any progress for this issue? We are meeting with the same issue.

darwink avatar Aug 04 '16 11:08 darwink

hi, is there any time schedule? i checked it everyday, but nothing happened.

ziyouchutuwenwu avatar Aug 08 '16 11:08 ziyouchutuwenwu

I'm blocked by this issue as well.

seanhess avatar Aug 08 '16 18:08 seanhess

I'm experiencing the first issue as well.

Client:
 Version:      1.12.0
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   8eab29e
 Built:        Thu Jul 28 21:04:48 2016
 OS/Arch:      darwin/amd64
 Experimental: true

AlexGustafsson avatar Aug 09 '16 15:08 AlexGustafsson

In this case, --net=host is working as expected... It's function however is not exactly intuitive on the mac ;)

The ability to set the --net, --pid, --ipc namespaces to host refers to host in the context of where the container engine is. In this case it is a Linux VM. So for every use of host, consider it to mean vm.

With that said, it would help us to understand what sort of applications need to run with --net=host so we can find a solution for this requirement. You can always use port mapping as an alternative... For example, docker run -p 8888:8888 will allow you to access your service at localhost:8888 from the Mac.

It might be easier to split this in to two issues to track being unable to access services running on the Mac from the container's default gateway IP address....

dave-tucker avatar Aug 09 '16 20:08 dave-tucker

@dave-tucker that clarifies things. Then how does one allow the container to access the mac host's interfaces (what host should mean imho)? Or is that a Linux only thing?

AlexGustafsson avatar Aug 09 '16 20:08 AlexGustafsson

@AlexGustafsson: thanks for the clarification. Allowing the container to be accessed via a specific Mac host interface sounds entirely reasonable to me. I had hoped something like docker run -p 10.0.0.1:80:80 would work, but unfortunately it fails because -- for historical reasons -- we try to bind to 10.0.0.1:80 on both the Mac and the VM, and unfortunately the VM doesn't have the same interface as the Mac. I'll investigate fixing this.

djs55 avatar Sep 07 '16 15:09 djs55

@ziyouchutuwenwu to telnet to a host port, you can telnet to the default gateway (192.168.65.1). For example I can run

$ docker run -it justincormack/debian bash
Unable to find image 'justincormack/debian:latest' locally
latest: Pulling from justincormack/debian
efd26ecc9548: Pull complete
a3ed95caeb02: Pull complete
2df06b6623ba: Pull complete
Digest: sha256:4c0acbaf234244e7a565b1ed0f3bbe87561d1c0440f5e9382941eb35bb8e518a
Status: Downloaded newer image for justincormack/debian:latest
root@9833dddf1ed1:/# ssh [email protected]
The authenticity of host '192.168.65.1 (192.168.65.1)' can't be established.
ECDSA key fingerprint is cc:ce:e0:0f:03:ae:1b:be:b3:28:8b:75:40:8c:ff:e3.
Are you sure you want to continue connecting (yes/no)?

Is this sufficient for your use-case?

djs55 avatar Sep 07 '16 15:09 djs55

@djs55 ,thank you for your help the actually ip gateway should be 192.168.1.1, 192.168.65.1 seems to be confused. For users, displaying the same ip address will much better than the confused digital 65 i think.

ziyouchutuwenwu avatar Sep 07 '16 23:09 ziyouchutuwenwu

not resolved for version

Version 1.12.1 (build: 12133)
2d5b4d9c3daa089e3869e6355a47dd96dbf39856
docker info
Containers: 1
 Running: 1
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 1.12.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 10
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: overlay bridge null host
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.4.20-moby
Operating System: Alpine Linux v3.4
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.953 GiB
Name: moby
ID: 57YZ:VNCF:YHUO:DG2H:67D2:TCYI:5FY7:FIZN:F4O7:XFAD:EGNN:3E4I
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 41
 System Time: 2016-09-16T21:44:52.575686599Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
docker version
Client:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.7.1
 Git commit:   6f9534c
 Built:        Thu Sep  8 10:31:18 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.12.1
 API version:  1.24
 Go version:   go1.6.3
 Git commit:   23cf638
 Built:        Thu Aug 18 17:52:38 2016
 OS/Arch:      linux/amd64

mac version

OS X EI Capitan
10.11.6(15G1004)

my docker test command

docker run -it --net=host  edib/elixir-phoenix-dev /bin/bash
ip address | grep 192

result is

inet 192.168.65.2/28 brd 192.168.65.15 scope global eth0

my host ip address is

192.168.1.55

ziyouchutuwenwu avatar Sep 16 '16 21:09 ziyouchutuwenwu

@ziyouchutuwenwu the resolution discussed above was not being able to use --net=host which as discussed is difficult to achieve but being able to bind specifically to a particular host interface with port publishing. We may be able to make --net=host work one day but there is currently no timetable for this, it needs significant engineering work.

justincormack avatar Sep 17 '16 10:09 justincormack

@justincormack thank you very much, i will use port mapping instead.

ziyouchutuwenwu avatar Sep 17 '16 12:09 ziyouchutuwenwu

@ziyouchutuwenwu, I'm curious why its hard to bind to a host interface?

djedi-bot avatar Oct 14 '16 16:10 djedi-bot

@justincormack thank you! I don't know why but this is the only answer I found in all the bugs on net host not currently working on docker for mac.

michaeljs1990 avatar Dec 04 '16 19:12 michaeljs1990

I was very surprised to see this not working in the new shiny macOS version of Docker (working in the intuitive way, not in the "yes, strictly speaking 'host' means 'vm' on macOS").

Is there a workaround when --net=host is required for the container to do e.g. uPnP discovery of the local network? Eg: https://home-assistant.io/components/discovery/

With the old Docker I could create a bridged adapter in VirtualBox to achieve this if I remember correctly?

torarnv avatar Dec 04 '16 21:12 torarnv

still doesn't work for version 1.12.6.

whoooami avatar Jan 15 '17 12:01 whoooami

Any update on this issue. I tried the latest docker and I still experiencing it.

lzomlot avatar Feb 08 '17 19:02 lzomlot

It appears it is possible for a standard xhyve install is able to allow access to the xhyve VM from the outside as indicated by the blog post at http://mifo.sk/post/xhyve-for-development

I think this would be the first step to properly supporting --net=host in Docker for Mac

Can someone from the Docker team investigate this?

manfredriem avatar Mar 10 '17 16:03 manfredriem

@justincormack you mentioned a while back this not having a timetable and needing significant engineering work... has there been any forward movement to put this on the timetable?

JockDaRock avatar Apr 04 '17 18:04 JockDaRock

i have similar issue but my problem is I got the 192.168.65.x ip as the manager node ip when running docker swarm init which will not work for any worker node wanna join the swarm created.

I would need to provide the --advertise-addr <my real host ip> to make the docker swarm working.

abgalphabet avatar Apr 22 '17 13:04 abgalphabet