如何在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)
答案 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