Can I get ip address inside my docker container?

后端 未结 9 1789
南旧
南旧 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

    You could also look for a line in /etc/hosts that ends with a container id and print the first field:

    sed -n 's/^\([0-9\.]*\)[[:blank:]]*[0-9a-f]\{12,\}$/\1/p' /etc/hosts
    

    I'd use awk, but standard awk in dedian:jessie doesn't support regex quantifiers like {12,}.

提交回复
热议问题