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

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

    On Ubuntu, hostname command can be used with the following options:

    • -i, --ip-address addresses for the host name
    • -I, --all-ip-addresses all addresses for the host

    For example:

    $ hostname -i
    172.17.0.2
    

    To assign to the variable, the following one-liner can be used:

    IP=$(hostname -i)
    

提交回复
热议问题