问题
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)
回答1:
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
回答2:
This command should display the IP
ping -q -c 1 docker.local | sed -En "s/^.*\((.+)\).*$/\1/p"
来源:https://stackoverflow.com/questions/58073936/how-to-get-ip-address-of-docker-desktop-vm