我正在使用Docker version 1.12.3
和docker-compose version 1.8.1
。我有一些服務,其中包含例如elasticsearch,rabbitmq和webappdocker-compose - 網絡 -/etc/hosts未更新
我的問題是服務無法通過其主機訪問其他服務因爲docker-compose不會將所有服務熱點放在/etc/hosts
文件中。我不知道他們的IP,因爲它是在docker-compose up
階段定義的。
我使用networks
功能,因爲它描述在https://docs.docker.com/compose/networking/而不是links
,因爲我做循環引用和links
不支持它。但使用networks
不會將所有服務主機放到每個服務節點/etc/hosts
文件中。我設置了container_name,我設置了主機名但沒有發生任何事情。我缺少的東西;
這是我的docker-compose.yml;
version: '2'
services:
elasticsearch1:
image: elasticsearch:5.0
container_name: "elasticsearch1"
hostname: "elasticsearch1"
command: "elasticsearch -E cluster.name=GameOfThrones -E node.name='Ned Stark' -E discovery.zen.ping.unicast.hosts=elasticsearch1,elasticsearch2,elasticsearch3"
volumes:
- "/opt/elasticsearch/data"
ports:
- "9200:9200"
- "9300:9300"
networks:
- webapp
elasticsearch2:
image: elasticsearch:5.0
container_name: "elasticsearch2"
hostname: "elasticsearch2"
command: "elasticsearch -E cluster.name=GameOfThrones -E node.name='Daenerys Targaryen' -E discovery.zen.ping.unicast.hosts=elasticsearch1,elasticsearch2,elasticsearch3"
volumes:
- "/opt/elasticsearch/data"
networks:
- webapp
elasticsearch3:
image: elasticsearch:5.0
container_name: "elasticsearch3"
hostname: "elasticsearch3"
command: "elasticsearch -E cluster.name=GameOfThrones -E node.name='John Snow' -E discovery.zen.ping.unicast.hosts=elasticsearch1,elasticsearch2,elasticsearch3"
volumes:
- "/opt/elasticsearch/data"
networks:
- webapp
rabbit1:
image: harbur/rabbitmq-cluster
container_name: "rabbit1"
hostname: "rabbit1"
environment:
- ERLANG_COOKIE=abcdefg
networks:
- webapp
rabbit2:
image: harbur/rabbitmq-cluster
container_name: "rabbit2"
hostname: "rabbit2"
environment:
- ERLANG_COOKIE=abcdefg
- CLUSTER_WITH=rabbit1
- ENABLE_RAM=true
networks:
- webapp
rabbit3:
image: harbur/rabbitmq-cluster
container_name: "rabbit3"
hostname: "rabbit3"
environment:
- ERLANG_COOKIE=abcdefg
- CLUSTER_WITH=rabbit1
networks:
- webapp
my_webapp:
image: my_webapp:0.2.0
container_name: "my_webapp"
hostname: "my_webapp"
command: "supervisord -c /etc/supervisor/supervisord.conf -n"
environment:
- DYNACONF_SETTINGS=settings.prod
ports:
- "8000:8000"
tty: true
networks:
- webapp
networks:
webapp:
driver: bridge
這就是我的理解,他們不能相互交流;
在elasticserach集羣初始化時出現此錯誤;
Caused by: java.net.UnknownHostException: elasticsearch3
而且這是我的泊塢窗,構成
docker-compose up
看起來對我來說很好。 Docker不再使用'/ etc/hosts',一切都通過內部DNS完成。你是說你的服務不能相互溝通?你打算怎麼打電話給他們?應該只能使用服務名稱。 – johnharris85
@ johnharris85,我更新了這個問題。我在elasticsearch集羣初始化中看到'由java.net.UnknownHostException:elasticsearch3引起,我只在我的本地Mac OS計算機上使用'docker-compose up'。 –