Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get mac host IP address from a docker container?

Tags:

docker

I want to access host IP address from a docker container on mac. I know how to do that on Linux by using the bridge0 interface. But docker for mac doesn't have bridge0. I tried to use the gateway 172.17.0.1 in a docker container but it doesn't work.

My docker for mac version is Docker version 1.13.0, build 49bf474.

I looked at this link https://github.com/docker/docker/issues/22753 but it mentions to create an alias on lo0 interface which I don't want to. Because our project is running inside docker container and I want to provides a general way without changing anything on the host.

Does anyone know how to do that in Mac?

like image 906
Joey Yi Zhao Avatar asked Jan 27 '17 03:01

Joey Yi Zhao


People also ask

How do I find the host IP of a Docker container?

You can easily get the IP address of any container if you have the name or ID of the container. You can get the container names using the "Docker ps -a" command. This will list all the existing containers.

Does a Docker container have a MAC address?

By default, the MAC address is generated using the IP address allocated to the container. You can set the container's MAC address explicitly by providing a MAC address via the --mac-address parameter (format: 12:34:56:78:9a:bc ).Be aware that Docker does not check if manually specified MAC addresses are unique.

How do I extract an IP address from a container?

If you run the inspect command on a container, you'll get a bunch of information, in JSON format. Scroll down until you find the key NetworkSettings , there look for the sub-key IPAddress . That's your container's IP address. > docker container inspect ubuntu-ip . . . "NetworkSettings": { . . . "IPAddress": "172.17.


1 Answers

From the Docker documentation :

I WANT TO CONNECT FROM A CONTAINER TO A SERVICE ON THE HOST

The Mac has a changing IP address (or none if you have no network access). From 17.06 onwards our recommendation is to connect to the special Mac-only DNS name docker.for.mac.localhost which will resolve to the internal IP address used by the host.

I think you'll need to upgrade your Docker For Mac version for this to work.

like image 108
tunecrew Avatar answered Sep 23 '22 16:09

tunecrew