将Docker父主机ip插入容器的hosts文件 [英] Insert Docker parent host ip into container's hosts file
问题描述
我是Docker的新人,想了解什么是将docker父主机ip插入到容器主机文件中的最佳方法。
I'm new to Docker and trying to understand what is the best way to insert docker parent host ip into container hosts file.
我正在使用以下命令在我的Docker文件中
I'm using the following command in my Dockerfile
RUN / sbin / ip route | awk'/ default / {print $ 3,\tdockerhost}'> > / etc / hosts
但有时主机ip得到更改,所以它不相关...
but sometimes hosts ip get change so its non relevant anymore...
如果你问自己,我需要访问另外2个码头容器(并且链接不提供此功能)。
The reason to do that, if you ask yourself, is that i need to access another 2 dockers containers (and link not offer this feature).
谢谢,
推荐答案
- 添加主机
这个。因此,在 docker run
命令中,请执行以下操作:
The --add-host
option is made for this. So, in your docker run
command, do something like:
docker run --add-host dockerhost:`/sbin/ip route|awk '/default/ { print $3}'` [my container]
这篇关于将Docker父主机ip插入容器的hosts文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!