Docker Community Forums

Share and learn in the Docker community.

How to determine the docker IP

docker

(Lyndon Washington) #1

In the past with docker-machine I could run the following command to determine the IP address:

docker-machine ip default

This proved a convenient way to setup env vars within shell scripts so I could do things like run psql from host and access the postgres container being used by my app.

Disclaimer: I realize that docker.local is supposed to be a shortcut way to avoid using IP addresses with Docker for Mac, but for me it currently does not work when connected through VPN. I am sure that will be fixed eventually.

In the interim, and as part of my transition from docker-machine centric scripts, the question I would like guidance on is how do you get the IP address of xhyve docker instance?

Cheers,
-Lyndon


(Maxim Tishchenko) #2

Hi hoshposh,
where can I read about “docker.local” ? And does it works for “docker for Mac” ?


(Lyndon Washington) #3

Maxim,

Not sure if there is a specific reference point to go to, but read the docs on the beta getting started page, and it is mentioned near the bottom when verifying if Docker for Mac is running successfully.

Cheers!


(Maxim Tishchenko) #4

I think you are talking about “Installing bash completion” section.

I have additional question regrading that section, should I uninstall docker-machine, docker-compose from brew (homebrew) before I add symlinks ?


(Lyndon Washington) #5

Actually the section labelled: “Step 3. Explore the application and run examples”, there it mentions using the ping docker.local to confirm the Docker for Mac is working!!

Not sure how we changed the direction of this topic, but in answer to your question . . .

should I uninstall docker-machine, docker-compose from brew (homebrew) before I add symlinks ?

Yes, I uninstalled those components from homebrew before I installed Docker for Mac, and Docker for Mac put in the links in the correct places.

Cheers!


(Frenchben) #6

@hoshposh Moving forward we’ll be using localhost as the source of truth instead of docker.local
This should allow your running host scripts to use localhost without having to do the leg work of getting the IP.


(Maxim Tishchenko) #7

Hi frenchben,
just localhost or with specific ports?


(Jamshid) #8

Does that mean running multiple docker servers locally won’t be supported with Docker for Mac? That’s useful for local swarm testing and for testing new docker versions.


(Lyndon Washington) #9

So the fix, as @frenchben indicated, is to go with the localhost, and to do that you can set native port forwarding to true:

pinata set native/port-forwarding true

Now I am able to use localhost to get to the container ports, and use the port introspection from docker-compose to get that assigned value.

Cheers!


(Kurt Madel) #10

But what if you want an IP that is accessible by other containers from both a browser on the host side (Mac) and from for container to container communication on the Docker host side (xhyve/alpine). It isn’t clear now how to find the host ip of the xhyve VM.


(Jamshid) #11

Agreed this is a problem. You can get the ip with this docker run but I don’t think it’s guaranteed.

$ docker run --net=host debian:jessie ip addr show | grep 192
    inet 192.168.64.18/24 scope global eth0

And it doesn’t really matter because when native/port-forwarding is true containers can’t access 192.168.64.18.

$ docker run -d --name aptcacherng --net=bridge -p "3142:3142" sameersbn/apt-cacher-ng 
$ curl -i 192.168.64.18:3142
HTTP/1.1 ...
$ docker run -ti centos curl -i 192.168.64.18:3142
curl: (7) Failed connect to 192.168.64.18:3142; Connection refused

I know containers should access each other by name (requires being on the same network) but it’s convenient to access by the published ip/port, and something like that is necessary if you’re trying to use a container (such as a build cache) from docker build.