Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No docker0 on docker for mac? #22753

Closed
NinoFloris opened this issue May 15, 2016 · 115 comments
Closed

No docker0 on docker for mac? #22753

NinoFloris opened this issue May 15, 2016 · 115 comments

Comments

@NinoFloris
Copy link

@NinoFloris NinoFloris commented May 15, 2016

Output of docker version:

Client:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   5604cbe
 Built:        Wed Apr 27 00:34:20 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.11.1
 API version:  1.23
 Go version:   go1.5.4
 Git commit:   8b63c77
 Built:        Tue May 10 10:39:20 2016
 OS/Arch:      linux/amd64

Output of docker info:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 21
Server Version: 1.11.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 25
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: null host bridge
Kernel Version: 4.4.9-moby
Operating System: Alpine Linux v3.3
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.954 GiB
Name: moby
ID: DFWG:ZZBI:QGZP:CAFF:PZVX:WLED:3XNK:J2LK:UV3V:X2JR:VCGJ:QFBK
Docker Root Dir: /var/lib/docker
Debug mode (client): false
Debug mode (server): true
 File Descriptors: 17
 Goroutines: 38
 System Time: 2016-05-15T23:53:58.530098977Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/

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

Steps to reproduce the issue:
1.
2.
3.

Describe the results you received:
No docker0 and absolutely no way to connect to services running on docker host via bridge gateway.
I have tried it all and thought I was going crazy, then I tried exactly the same things on my ubuntu host with zero problems

Describe the results you expected:
I would like to be able to connect to my local redis and other services without having to dockerize these...

@HackToday
Copy link
Contributor

@HackToday HackToday commented May 16, 2016

did you find ip in virtualbox or on host ?

I think the docker0 was on the virtualbox VM.

@NinoFloris
Copy link
Author

@NinoFloris NinoFloris commented May 16, 2016

Im talking about docker for mac that is in beta and does not do its work via a vm

@MiteshSharma
Copy link

@MiteshSharma MiteshSharma commented May 16, 2016

I am also facing exact same issue. Found ip address of host on docker machine using below command. Assuming 0.0.0.0 represent host, correct me if i am wrong here.
netstat -nr | grep '^0.0.0.0' | awk '{print $2}'
172.17.0.1

but when do curl on this ip with a port where i am running a web server it gives connection refused.
curl 172.17.0.1:9000
curl: (7) Failed to connect to 172.17.0.1 port 9000: Connection refused

Not sure how to get proper fix. This seems to be giving trouble as need to connect to service which will run on host machine.
Also found a way to fix ip address of host machine by setting it in DOCKER_OPTS.
DOCKER_OPTS="-H tcp://0.0.0.0:5000 -H unix:///var/run/docker.sock --bip=172.17.42.1/16"

but where on mac can i put this options? on ubuntu it can be placed at /etc/default/docker.

Please provide directions if this can be fixed on mac.

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 16, 2016

ping @justincormack perhaps you have some hints here.

@NinoFloris
Copy link
Author

@NinoFloris NinoFloris commented May 16, 2016

@MiteshSharma exactly, that is one of the first things I tried as well and with exactly the same problems

@MiteshSharma
Copy link

@MiteshSharma MiteshSharma commented May 16, 2016

@NinoFloris Seems like we both are exact same place. In my case i am running mysql on my host machine.
Hey guys,
Do update if someone is able to do this.

@HackToday
Copy link
Contributor

@HackToday HackToday commented May 16, 2016

I used this
https://docs.docker.com/engine/installation/mac/

not sure if your beta any special

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 16, 2016

@HackToday that's different, that's the VirtualBox based Mac installation; Docker for Mac is on beta.docker.com

@HackToday
Copy link
Contributor

@HackToday HackToday commented May 17, 2016

Thanks @thaJeztah Any possible good doc link for related Mac Docker architecture or something else details? Seems interesting

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 17, 2016

@HackToday https://blog.docker.com/2016/03/docker-for-mac-windows-beta/ gives a little more, and there is documentation, but I think it's only if you are in the beta; https://beta.docker.com/docs/. If you sign-up for the beta, then give me a "ping"; I can try to get you on the priority list as a contributor 😄

@HackToday
Copy link
Contributor

@HackToday HackToday commented May 17, 2016

oh @thaJeztah Thanks, I thought it was a free to work and try. Not need any special to contribute. I will read that blog first to understand before I try. 😺

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented May 17, 2016

@HackToday it's completely free, just to not overwhelm the team, it was decided to release it as a "private" beta first, because "many users' === "many support questions" 😄

@justincormack
Copy link
Contributor

@justincormack justincormack commented May 17, 2016

Hi, yes there is not currently a way to route from the Mac to the docker0 bridge. We may be able to add this later, but generally we would recommend you connect from a container, or by exposing ports. This is the same as with docker overlay networks as well on Linux, which you cannot connect to from the host.

@NinoFloris
Copy link
Author

@NinoFloris NinoFloris commented May 17, 2016

Well not really satisfactory as macs are usually not production servers but
dev machines.

On my production machines i dont mind the problem of not being able to
connect to the host.

But on a dev machine connecting to services on the same host from inside a
container is exactly the scenario where this functionality is desired the
most.

@advoretsky
Copy link

@advoretsky advoretsky commented May 30, 2016

I need this docker0 interface too for using in mixed "docker + on host (from IDE) running apps" environment.

@justincormack
Copy link
Contributor

@justincormack justincormack commented Jun 1, 2016

The current best solution is to connect to your containers from another container. At present there is no way we can provide routing to these containers due to issues with OSX that Apple have not yet resolved. we are tracking this requirement, but we cannot do anything about it at present.

@igrayson
Copy link

@igrayson igrayson commented Jun 4, 2016

Is the above comment accurate?

I found that, from within docker-for-mac-beta containers, the docker host could be found and connected to at the usual 172.17.0.1 address (assuming the service bound to 0.0.0.0).

@cpuguy83
Copy link
Contributor

@cpuguy83 cpuguy83 commented Jun 5, 2016

@igrayson This is because the containers are in the VM with the docker daemon and can certainly access it.
The issue is routing from OSX into the VM net.

@igrayson
Copy link

@igrayson igrayson commented Jun 5, 2016

The issue is routing from OSX into the VM net.

That's not my understanding of the OP issue:

I would like to be able to connect to my local redis and other services without having to dockerize these...

I am running docker-for-mac-beta, and have no trouble connecting to redis and other local services -- running on OSX -- by having them listen on 0.0.0.0, and having my dockerized apps connect to 172.17.0.1.

@thalesfsp
Copy link

@thalesfsp thalesfsp commented Jun 8, 2016

Overview

I have the same problem. Using Docker version 1.11.1-beta14 (build: 8670) 984649fbd63d53a62b34f08b59694d4d569b74d5. My pinata doctor says everything is ok.

I cannot curl a service running in host, for example an ExpressJS application listening in the port 3001, from inside the container:

root@e19fc8e02595:/# curl localhost:3001
curl: (7) Failed to connect to localhost port 3001: Connection refused

root@e19fc8e02595:/# curl 0.0.0.0:3001
curl: (7) Failed to connect to 0.0.0.0 port 3001: Connection refused

root@e19fc8e02595:/# curl 172.25.8.25:3001
{"status":200} 
root@e19fc8e02595:/#

Note: 172.25.8.25 is my WiFi IP.

Pinata

$pinata list
These are advanced configuration settings to customize Docker.app on MacOSX.
You can set them via pinata set <key> <value> <options>.

🐳  hostname = docker
   Hostname of the virtual machine endpoint, where container ports will be
   exposed if using nat networking. Access it via 'docker.local'.

🐳  hypervisor = native (memory=4, ncpu=6)
   The Docker.app includes embedded hypervisors that run the virtual machines
   that power the containers. This setting allows you to control which the
   default one used for Linux is.

 ▸  native: a version of the xhyve hypervisor that uses the MacOSX
              Hypervisor.framework to run container VMs. Parameters:
              memory (VM memory in gigabytes), ncpu (vCPUs)


🐳  network = hostnet (docker-ipv4=192.168.65.2, host-ipv4=192.168.65.1)
   Controls how local containers can access the external network via the
   MacOS X host. This includes outbound traffic as well as publishing ports
   for external access to the local containers.

 ▸ hostnet: a mode that helps if you are using a VPN that restricts
              connectivity. Activating this mode will proxy container network
              packets via the Docker.app process as host socket traffic.
              Parameters: docker-ipv4 (docker node), host-ipv4 (host node)
 ▸     nat: a mode that uses the MacOS X vmnet.framework to route container
              traffic to the host network via a NAT.

🐳  filesystem = osxfs
   Controls the mode by which files from the MacOS X host and the container
   filesystem are shared with each other.

 ▸   osxfs: a FUSE-based filesystem that bidirectionally forwards OSX
              filesystem events into the container.


🐳  native/port-forwarding = true
   Expose container ports on the Mac, rather than the VM

 ▸    true: Container ports will be exposed on the Mac
 ▸   false: Container ports will be exposed on the VM

🐳  daemon = run 'pinata get daemon' or 'pinata set daemon [@file|-]>
   JSON configuration of the local Docker daemon. Configure any custom
   options you need as documented in:
   https://docs.docker.com/engine/reference/commandline/daemon/. Set it
   directly, or a @file or - for stdin.

Possible duplicates, references, help and etc

@exit99
Copy link

@exit99 exit99 commented Jul 15, 2016

I had similiar issues and found 172.* ips would not let me connect to a local mysql instance binded to 0.0.0.0.

I could connect to it with any routable IP address from my host machine. ifconfig and find one of yours.

Now how do I get this dynamically into the container?

@nikdavis
Copy link

@nikdavis nikdavis commented Jul 16, 2016

Having the same issue as @Kazanz (mysql running on locally/uncontained) trying 172.17.0.1. So I guess I'll try the Docker Toolbox? It would be helpful if this constraint was documented. I couldn't find anything about it until I stumbled upon this issue.

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jul 16, 2016

Ping @londoncalling ^^

@rioastamal
Copy link

@rioastamal rioastamal commented Jul 20, 2016

Any news about this one? because in Ubuntu (host) the application inside container which listen on 0.0.0.0 can be contacted by the host using IP 172.17.*.*.. So no need to expose port when running the container.

On Docker for Mac Beta I can not do that because the absent of docker0. Hope it getting fixed on the final release :)

@londoncalling
Copy link
Contributor

@londoncalling londoncalling commented Jul 20, 2016

@thaJeztah @astasoft I'll look into it today, thanks@

@chanezon
Copy link

@chanezon chanezon commented Jul 20, 2016

My understanding is that your issue is accessing services running on your Mac from a container.
If that is the case, you can do that using the ip address exposed by en0 interface.
ifconfig en0 | grep "inet " | cut -d " " -f2

For example, if I have a web server running on my Mac on port 80:
docker run -it tutum/curl curl ifconfig en0 | grep "inet " | cut -d " " -f2

It works!

You could set that ip in an environment variable and pass that to your container, like I do for the X11 server in https://github.com/chanezon/docker-tips/blob/master/x11/README.md

@justincormack
Copy link
Contributor

@justincormack justincormack commented Feb 27, 2017

@cristiangrama
Copy link

@cristiangrama cristiangrama commented Mar 30, 2017

@rogaha 192.168.65.1 is not working on my end. How did you find out about that IP?

@geerlingguy
Copy link

@geerlingguy geerlingguy commented May 5, 2017

I just wanted to add a +1/subscribe along with everyone else in this thread, and add another voice to the feature request of being able to easily access docker containers through the bridge interface on unique/custom IP addresses.

I was ramming my head into the wall for at least 4 hours trying to figure out why I couldn't get any documented examples working, until I somehow found this issue, describing the problem perfectly.

For now, the workaround mentioned by @justincormack (#22753 (comment)) seems to work passably well. I'm adding experimental Docker support to Drupal VM using the instructions:

  1. Add a host to /etc/hosts with sudo /etc/hosts (e.g. 192.168.1.100 mysite.dev)

  2. Create an alias on the loopback interface: sudo sudo ifconfig lo0 alias 192.168.1.100/24

  3. Bring up a container with the following pseudocompose:

     version: "3"
     
     services:
       app:
         image: image-name
         ports:
           - 192.168.1.100:80:80
           - 192.168.1.100:443:443
         [...]
    

This seems to work perfectly for me, and though it currently requires a couple manual steps (which are avoided if using other tools on top of Docker... something I don't want to force my users to do), it allows me to almost reach Docker nirvana on Mac.

So thanks for the workaround, and I hope you can find a way to get the bridge network working soon (or just abandon macOS < 10.12 😏)

@TheAntonioReyes
Copy link

@TheAntonioReyes TheAntonioReyes commented May 5, 2017

@rogaha thank you sooo much, 192.168.65.1 has solved my issue. I hope this doesn't get changed in the future, unless they find a cleaner solution. As of Docker for Mac 17.0.3.1 this has allowed my container to talk to the MySQL server running on my machine's localhost.

@rogaha
Copy link
Contributor

@rogaha rogaha commented May 5, 2017

@TheAntonioReyes I'm glad it worked for you. Thanks for the feedback!

@diemol
Copy link

@diemol diemol commented Jul 7, 2017

Hi,

I am reading the docs here: https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds, and I am trying to use the the special Mac-only DNS name mentioned there: docker.for.mac.localhost.

If I do a ping on a terminal inside the docker container, it gets resolved to 192.168.65.1, and doing a curl to an app running on my mac retrieves the expected result.

I am using this image: https://github.com/elgalu/docker-selenium, and I can open a Chrome browser there. So I wanted to go to http://docker.for.mac.localhost:80, and the connection was refused. However, doing http://192.168.65.1:80 works.

Am I missing something? I wanted to start using the docker.for.mac.localhost.

I am using this: Version 17.06.0-ce-mac18 (18433)

EDIT: Seems this only happens on Chrome and this issue explains it. docker/for-mac#1837

@atuttle
Copy link

@atuttle atuttle commented Aug 31, 2017

I think that using docker.for.mac.localhost was a poor decision. The whole point of containers is that they are portable and should have no dependency on what type of host they reside. If my team is half Windows users and half Mac, then the code inside of our containers will have to be configured differently.

I'm glad there's a hostname approach, I just think the meeting where this approach was decided should have lasted 5 more minutes.

@SeanCannon
Copy link

@SeanCannon SeanCannon commented Sep 18, 2017

@AbimbolaE
Copy link

@AbimbolaE AbimbolaE commented Oct 30, 2017

I worked around this problem by reverting back to docker-machine for Mac. The docker machine VM is a Linux distro which means that it creates a docker0 interface which has access to the private network range of the docker containers. Then, on my host mac machine, I created a route for the 172.18.x.x address range of the containers which points to the ip address of the docker machine instance (192.168.99.100 in my case).

This allows packets destined for the private container network to be forwarded by my mac OS to the IP address of the linux VM of docker machine, which knows how to reach the private containers and forwards the packets to them directly.

Creating the route to the docker machine vm for the private container network

sudo route -n add -net 172.18.0.0/16 192.168.99.100

You can get the address for the container network by using docker network inspect or docker inspect <container_name>.

@arefaslani
Copy link

@arefaslani arefaslani commented Jun 27, 2018

You can find ip of the host in docker for mac by running this command:

docker run busybox ping -c 1 docker.for.mac.localhost | awk 'FNR==2 {print $4}' | sed s'/.$//'
@daniel-wiredscore
Copy link

@daniel-wiredscore daniel-wiredscore commented Dec 24, 2018

Run this command

docker run -i -d --expose=80 <container_name> bash

Then get the ip address from

docker ps

if it says 0.0.0.0 then that will work fine once the port is exposed or any other ip address written there.

@pauldraper
Copy link

@pauldraper pauldraper commented Jul 14, 2019

The solution is actually relatively simple; IDK why Docker does not fix it.

See https://github.com/AlmirKadric-Published/docker-tuntap-osx for a workaround that shims the hyperkit binary.

@pauldraper
Copy link

@pauldraper pauldraper commented Jul 31, 2019

Partial duplicate of #155 (and #171, #515, #3484).

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Mar 5, 2020

I'm closing. This is by design and anyway unrelated to this repo.

@AkihiroSuda AkihiroSuda closed this Mar 5, 2020
@johnnyutahh
Copy link

@johnnyutahh johnnyutahh commented Mar 24, 2020

The following works wonderfully for me. No intermediate containers, no DNS workaround.

From https://github.com/AlmirKadric-Published/docker-tuntap-osx#how-it-works :

Once done the IP address 10.0.75.2 can be used as a network routing gateway to reach any containers within the Host Virtual Machine:
route add -net <IP RANGE> -netmask <IP MASK> 10.0.75.2

Thank you @pauldraper (!).

@pauldraper commented on Jul 14, 2019

The solution is actually relatively simple; IDK why Docker does not fix it.

See https://github.com/AlmirKadric-Published/docker-tuntap-osx for a workaround that shims the hyperkit binary.

My macOS version:

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.14.6
BuildVersion:	18G3020
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet