Docker 撰写自动设置链接

Docker Compose automatically setting links

Docker 当我启动时,compose 似乎会自动在主机文件中设置链接:

root@47f648654cc9:/opt/mio# cat /etc/hosts
172.17.1.54     47f648654cc9
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.1.54     mio-events-service.bridge
172.17.1.52     mongodb.bridge
172.17.1.54     mio-events-service
172.17.1.52     mongodb
172.17.1.53     consul
172.17.1.53     consul.bridge
172.17.1.55     registrator
172.17.1.55     registrator.bridge
172.17.1.56     kv-registration
172.17.1.56     kv-registration.bridge
172.17.1.57     rabbitmq
172.17.1.57     rabbitmq.bridge

即我不必在 docker-compose.yml 中提供 "links:" 元素来获取容器之间的链接。这似乎与文档相矛盾。知道为什么要这样做吗?

谢谢

尼克

更新

这是我的撰写文件

consul:
  image: registry.systems.com/consuld
  container_name: consul
  ports:
    - "8400:8400"
    - "8500:8500"
    - "53:8600/udp"
  environment:
    - IP=192.168.99.100
  hostname: dockermachine

registrator:
  image: gliderlabs/registrator:latest
  container_name: registrator
  command: consul://consul:8500
  volumes:
    - "/var/run/docker.sock:/tmp/docker.sock"
  links:
    - consul

kv-registration:
  image: registry.systems.com/nativ/consul-local-kv-registration
  container_name: kv-registration
  links:
    - consul

rabbitmq:
  image: rabbitmq
  container_name: rabbitmq
  ports:
    - 4369:4369
    - 5672:5672
    - 15672:15672
    - 25672:25672

mongodb:
  image: mongo
  container_name: mongodb
  ports:
    - 27017:27017
    - 28017:28017

mio-events-service:
  image: registry.systems.com/mio-events-service:1.0.190
  container_name: mio-events-service
  ports:
    - 18113:18113
  extra_hosts:
   - "dockermachine:192.168.99.100"

我认为您正在使用 --x-networking 替换链接,并为同一网络上的每个容器添加这些主机条目。

http://docs.docker.com/compose/networking/