How to get the IP address of the docker host from inside a docker container

后端 未结 24 1412
鱼传尺愫
鱼传尺愫 2020-11-22 06:41

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.

24条回答
  •  抹茶落季
    2020-11-22 07:20

    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 )

提交回复
热议问题