docker乘以一个容器的主机名

时间:2016-10-05 09:16:01

标签: docker docker-compose dockerfile

如何在docker-compose中为某些docker添加多个主机名?容器应该通过自己看多个主机名,例如:

ping name: should resolve 127.0.0.1 (or $docker_ip)
ping another.name: should resolve 127.0.0.1 (or $docker_ip)

1 个答案:

答案 0 :(得分:1)

使用extra-hosts

extra_hosts:
 - "name:127.0.0.1"
 - "another.name:127.0.0.1"

docker run --add-host具有相同的效果:

> docker run --add-host another.name:127.0.0.1 sixeyed/ubuntu-with-utils ping another.name
PING another.name (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.057 ms