如何使docker容器使用主机的/ etc / hosts文件? [英] How can you make the docker container use the host machine's /etc/hosts file?
问题描述
/ etc / hosts
设置。有没有办法这样做? 我知道有一个 - 添加主机
选项与docker运行,但这不是我想要的,因为主机的 / etc / hosts
文件在不同的机器上可能不同,所以对于我来说,使用 - add-host $ c $来硬编码确切的IP /主机并不好c>。
另一个解决方案是使用 - net = host
在docker运行命令。这告诉Docker使容器使用主机的网络堆栈。您可以在这里了解更多信息: https://docs.docker.com/v1.8/articles/networking/
I want to make it so that the docker container I spin up use the same /etc/hosts
settings as on the host machine I run from. Is there a way to do this?
I know there is an --add-host
option with docker run but that's not exactly what I want because the host machine's /etc/hosts
file may be different on different machines so it's not great for me to hardcode exact IP/hosts with --add-host
.
Another solution is to use --net=host
in the docker run command. This tells Docker to make the container use the host's network stack. You can learn more here: https://docs.docker.com/v1.8/articles/networking/
这篇关于如何使docker容器使用主机的/ etc / hosts文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!