13

I'm in a team where some of us use docker toolbox and some user docker desktop. We're writing an application that needs to communicate to a docker container in development.

On docker toolbox, I know the docker-machine env command sets the docker host environment variable and I can use that to get the ip of the virtual machine that's running the docker engine. From there I just access the exposed ports.

What's the equivalent way to get that information on docker desktop? (I do not have a machine that has docker desktop, only docker toolbox but I'm writing code that should be able to access the docker container on both)

4 Answers 4

25

On windows OS, after installed docker, there is an entry added by docker inside your hosts file (C:\Windows\System32\drivers\etc\hosts), which states the IP as:

Added by Docker Desktop

10.xx.xx.xx host.docker.internal

Sign up to request clarification or add additional context in comments.

3 Comments

I found (Docker 19.03.8) multiple entries in my hosts file, unfortunately the default resolutor did not pick the right one and I had to set it manually. It is dynamically allocated so it may change. If you know the exposed port you may run netstat -na to find the real ip address you should use.
I get 127.0.0.1 kubernetes.docker.internal
@Pathros - on Windows, If you have Docker Desktop installed, a few lines above that you should see a line for host.docker.internal.
5

Below section got added in my /etc/hosts:

# Added by Docker Desktop 192.168.99.1 host.docker.internal 192.168.99.1 gateway.docker.internal 

Then I was able to access by adding the port to which the app was bind to.

Comments

0

This command should display the IP

ping -q -c 1 docker.local | sed -En "s/^.*\((.+)\).*$/\1/p" 

5 Comments

Is there another way to do this? The code that I'm writing is not going to be able to ping. Also, is there a way to get the container accessible on the localhost?
On docker, you can always expose ports to expose services on the container to the host machine. Also, as of version 18.03, you can use host.docker.internal as the host's IP.
I'm talking from the host machine and not inside the container. Thank you for the replies.
I only get a two digit number. What does it mean?
Mac: "ping: cannot resolve docker.local: Unknown host"
-1

ipconfig can get you this information as well

1 Comment

Kind of true as "ping host.docker.internal" (on Windows) actually gives out your WLAN IP, and on ipconfig you can see another VEthernet connection IP which also maps to Docker

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.