How to get IP Address of Docker Desktop VM?

风格不统一 提交于 2020-05-17 08:10:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!