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

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

    Here is how I do it. In this case, it adds a hosts entry into /etc/hosts within the docker image pointing taurus-host to my local machine IP: :

    TAURUS_HOST=`ipconfig getifaddr en0`
    docker run -it --rm -e MY_ENVIRONMENT='local' --add-host "taurus-host:${TAURUS_HOST}" ...
    

    Then, from within Docker container, script can use host name taurus-host to get out to my local machine which hosts the docker container.

提交回复
热议问题