How to get the IP address of the docker host from

2019-01-01 11:42发布

As the title says. I need to be able to retrieve the IP address the docker hosts and the portmaps from the host to the container, and doing that inside of the container.

标签: docker ip
15条回答
心情的温度
2楼-- · 2019-01-01 12:31

The only way is passing the host information as environment when you create a container

run --env <key>=<value>
查看更多
看淡一切
3楼-- · 2019-01-01 12:34

The --add-host could be a more cleaner solution (but without the port part, only the host can be handled with this solution). So, in your docker run command, do something like:

docker run --add-host dockerhost:`/sbin/ip route|awk '/default/ { print  $3}'` [my container]

(From https://stackoverflow.com/a/26864854/127400 )

查看更多
荒废的爱情
4楼-- · 2019-01-01 12:36

Docker for Mac I want to connect from a container to a service on the host

The host has a changing IP address (or none if you have no network access). From 18.03 onwards our recommendation is to connect to the special DNS name host.docker.internal, which resolves to the internal IP address used by the host.

The gateway is also reachable as gateway.docker.internal. https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds

查看更多
登录 后发表回答