Can I get ip address inside my docker container?

后端 未结 9 1817
南旧
南旧 2020-12-28 12:10

How to get container ip address inside this container?

\'docker inspect $hostname ...\' not suitable, because I don\'t share /var/run/docker.sock host file to contai

9条回答
  •  余生分开走
    2020-12-28 12:33

    I can find the IP address with

    hostname -i
    

    Of course, that may not be completely accurate if there is more than one interface.

    Edit

    Note: According to the hostname man page, hostname -i uses DNS to resolve the ip address, where hostname -I displays all the addresses except loopback, does not depend on DNS, and is recommended.

    In all my Docker containers, -i and -I return the same results (but this is not the case on my desktop).

提交回复
热议问题