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

后端 未结 24 1767
鱼传尺愫
鱼传尺愫 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:29

    In linux you can run

    HOST_IP=`hostname -I | awk '{print $1}'`
    

    In macOS your host machine is not the Docker host. Docker will install it's host OS in VirtualBox.

    HOST_IP=`docker run busybox ping -c 1 docker.for.mac.localhost | awk 'FNR==2 {print $4}' | sed s'/.$//'`
    

提交回复
热议问题