Docker群上的分布式Java应用程序

我是新来的docker,我试图在docker群上运行一个分布式的JAVA应用程序。 我使用命令docker-compose在一个节点上testing它,它工作正常。

当我尝试使用该命令将其作为服务进行部署时

docker stack deploy --compose-file myfile.yml myapp 

组件“im”不能连接组件“orchestrator”

我使用标签“orchestrator”作为组件的IP地址(它与简单的组合)

任何帮助? 在我的撰写文件下面

我已经创build了一个撰写文件:

 version: "3" services: zk: image: xxx/cep deploy: mode: replicated replicas: 1 entrypoint: /ext-sw/zookeeper-3.4.5/bin/zkServer.sh command: start-foreground ports: - 2181:2181 networks: - cepnet orchestrator: image: xxx/cep deploy: mode: replicated replicas: 1 entrypoint: /bin/runOrchestrator ports: - 9000:9000 depends_on: - zk networks: - cepnet im: image: xxx/cep deploy: mode: replicated replicas: 1 entrypoint: /bin/runIM -IP im -PORT 9901 -ID im1 -LOGID im1 ports: - 9901:9901 depends_on: - orchestrator networks: - cepnet networks: cepnet: enter code here 

编辑:正如在评论中说,我原来的问题是由docker指派给一个容器的IP。

在ping命令的输出下面使用服务名称和主机名称运行

 root@90cfe6fc88ed:~# ping orchestrator PING orchestrator (10.0.0.9) 56(84) bytes of data. 64 bytes from 10.0.0.9: icmp_seq=1 ttl=64 time=0.032 ms 64 bytes from 10.0.0.9: icmp_seq=2 ttl=64 time=0.034 ms 64 bytes from 10.0.0.9: icmp_seq=3 ttl=64 time=0.033 ms ^C --- orchestrator ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2010ms rtt min/avg/max/mdev = 0.032/0.033/0.034/0.000 ms root@90cfe6fc88ed:~# ping $(hostname) PING 90cfe6fc88ed (10.0.0.10) 56(84) bytes of data. 64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=1 ttl=64 time=0.055 ms 64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=2 ttl=64 time=0.018 ms 64 bytes from 90cfe6fc88ed (10.0.0.10): icmp_seq=3 ttl=64 time=0.014 ms ^C --- 90cfe6fc88ed ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2033ms rtt min/avg/max/mdev = 0.014/0.029/0.055/0.018 ms 

如文档中所述, depends_on在群集上不受支持。 您的应用程序需要能够处理您所依赖的服务不在运行的情况(例如尝试重新连接,直到可用)

如果你想testing是否真的是这个问题,等待所有服务运行,然后docker工杀死你有问题连接的服务。 如果它运行的很好,那么很明显,它会期望其他服务已经运行。