我正在使用Docker version 1.12.3和docker-compose version 1.8.1。我有一些服务,例如elasticsearch、rabbitmq和一个webapp
我的问题是,一个服务不能通过它的主机访问另一个服务,因为端口-组合并不会将所有的服务热放在/etc/hosts文件中。我不知道他们的IP,因为它是在docker-compose up阶段定义的。
我使用networks特性,因为它是在https://docs.docker.com/compose/networking/而不是links中描述的,因为我做循环引用,而links不支持它。但是,使用networks并不会将所有服务主机都放到每个服务节点上,/etc/hosts文件。我设置了container_name,设置了主机名,但是什么都没有发生。我错过了什么;
这是我的船坞--复合船坞。
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这就是我所理解的,他们不能相互融合;
在弹性教育集群初始化中,我得到了这个错误;
Caused by: java.net.UnknownHostException: elasticsearch3
这就是我在码头作曲的方式
docker-compose up
发布于 2016-11-16 18:13:56
如果容器希望在容器启动时立即可用主机名,这很可能是失败的原因。
在其他容器启动之前,主机名将不存在。您可以使用入口点脚本等待直到所有主机名都可用,然后是exec elasticsearch ...
https://stackoverflow.com/questions/40638531
复制相似问题