我可以在Docker容器中获取IP地址吗? [英] Can I get ip address inside my docker container?
本文介绍了我可以在Docker容器中获取IP地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在此容器中获取容器ip地址?
How to get container ip address inside this container?
'docker inspect $ hostname ...'不适合,因为我不共享/ var / run /docker.sock将主机文件存储到容器中。
'docker inspect $hostname ...' not suitable, because I don't share /var/run/docker.sock host file to container.
推荐答案
由于IP地址位于/ etc / hosts的第一行,可以在容器中执行awk命令,该命令显示/ etc / hosts第一行的第一个单词
As the IP address is in the first line of /etc/hosts, you can do in a container the awk command that prints the first word of the first line of /etc/hosts
$ awk 'END{print $1}' /etc/hosts
172.17.0.14
这篇关于我可以在Docker容器中获取IP地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文