如何使docker容器使用主机的/ etc / hosts文件? [英] How can you make the docker container use the host machine's /etc/hosts file?

查看:694
本文介绍了如何使docker容器使用主机的/ etc / hosts文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要这样做,以便我启动的docker容器使用与我运行的主机相同的 / etc / hosts 设置。有没有办法这样做?



我知道有一个 - 添加主机 选项与docker运行,但这不是我想要的,因为主机的 / etc / hosts 文件在不同的机器上可能不同,所以对于我来说,使用 - add-host

解决方案

另一个解决方案是使用 - 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆