Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker for Mac VM IP

I just migrated to using Docker for Mac, from previously using Docker Toolbox with virtualbox for OSX.

I used to get the machine IP address with $(docker-machine ip default).

Is there a reliable way to get the Hyperkit IP address?

Thanks!

like image 714
mac Avatar asked Dec 21 '16 16:12

mac


People also ask

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.

What IP address is Docker using?

Usually Docker uses the default 172.17. 0.0/16 subnet for container networking.

Does Docker for Mac use a VM?

Docker is a full development platform for creating containerized apps, and Docker for Mac is the most efficient way to start and run Docker on your MacBook. It runs on a LinuxKit VM and NOT on VirtualBox or VMware Fusion.


2 Answers

In opposition to Docker toolbox, Docker for Windows and Docker for Mac are designed to give you the feeling that Docker is running directly on your OS, so they use lightweight virtual machines running under lightweight hypervisors (instead of VirtualBox) handled directly by the docker executable.
Hence you won't see them with docker-machine and you won't see another IP address than localhost.

Docker for Windows relies on the HyperV hypervisor which allows a network connection to tcp://localhost:2375.

Docker for Mac relies on the xhyve hypervisor, the way it's implemented only provides a connection through the socket unix:///var/run/docker.sock.

Workaround

To provide a TCP connection for Docker for Mac:

  1. Install socat. With brew:

    brew install socat

  2. Run this socat command to forward TCP requests to the socket

    socat TCP-LISTEN:2375,reuseaddr,fork,bind=localhost UNIX-CONNECT:/var/run/docker.sock

  3. Map what you want on tcp://localhost:2375

Up to you to run the socat command on startup, if necessary.

This was for instance useful to me to associate the Webstorm nodeJS debugger to a nodeJS container (since at the time of writing, docker debugging is supported by Webstorm docker integration plugin, but not through unix sockets).

Documentation on Docker for Mac limitations

https://docs.docker.com/docker-for-mac/networking/#/known-limitations-use-cases-and-workarounds

There is no docker0 bridge on macOS

Because of the way networking is implemented in Docker for Mac, you cannot see a docker0 interface in macOS. This interface is actually within HyperKit.

like image 131
arvymetal Avatar answered Oct 19 '22 21:10

arvymetal


There's no need for working with the xhyve VM's IP address directly like you would with docker-machine. All port mappings are directly mapped to localhost.

$ docker run -d -p 8080:80 nginx:latest
$ curl localhost:8080

Also see the official documentation:

When you run a container with the -p argument, for example: $ docker run -p 80:80 -d nginx Docker for Mac will make the container port available at localhost.

like image 32
helmbert Avatar answered Oct 19 '22 21:10

helmbert