How can you make the docker container use the host

2019-01-31 11:49发布

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.

标签: docker
7条回答
时光不老,我们不散
2楼-- · 2019-01-31 12:52

Add standard host file -

docker run -it ubuntu cat /etc/hosts

Add a mapping for server 'foo' -

docker run -it --add-host foo:10.0.0.3 ubuntu cat /etc/hosts

Add mappings for multiple servers

docker run -it --add-host foo:10.0.0.3 --add-host bar:10.7.3.21 ubuntu cat /etc/hosts

Reference - http://jasani.org/2014/11/19/docker-now-supports-adding-host-mappings/

查看更多
登录 后发表回答