Docker for Windows – 调用部署在另一个容器上的另一个Java应用程序时,部署在容器上的Java应用程序获取连接拒绝错误

我使用的是旧版Docker Toolbox for Windows,所以我卸载了它并安装了最新的稳定的Docker for Windows。

我有两个Java应用程序运行在自己的容器上:

  • Application1: http:// archimedes1:8761
  • Application2: http:// archimedes2:8762

在这两个应用程序中使用的Dockerfile

FROM frolvlad/alpine-oraclejdk8:slim VOLUME /tmp ADD archimedes-0.0.1-SNAPSHOT.jar app.jar RUN sh -c 'touch /app.jar' ENV JAVA_OPTS="-Xms750m -Xmx750m" ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ] 

我修改了我的Windows / etc / hosts以使archimedes1 \ 2映射127.0.0.1(与之前的Docker Toolbox映射192.168.99.100):

 127.0.0.1 archimedes1 127.0.0.1 archimedes2 

这是我如何启动容器(注意使用–add-host使容器知道主机名):

 docker run -e "SPRING_PROFILES_ACTIVE=archimedes1" -p 8761:8761 --name archimedes1 --add-host archimedes1:127.0.0.1 --add-host archimedes2:127.0.0.1 -d storyteller/archimedes docker run -e "SPRING_PROFILES_ACTIVE=archimedes2" -p 8762:8762 --name archimedes2 --add-host archimedes1:127.0.0.1 --add-host archimedes2:127.0.0.1 -d storyteller/archimedes 

与Docker Toolbox一起工作,但是因为我安装了Docker for Windows容器,当彼此联系时显示一个Connection Refused错误。 在这种情况下,阿基米德2试图呼叫阿基米德1:

 2017-01-25 13:10:27.406 DEBUG 5 --- [t_archimedes1-2] cndshared.MonitoredConnectionManager : Get connection: {}->http://archimedes1:8761, timeout = 200 2017-01-25 13:10:27.406 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : [{}->http://archimedes1:8761] total kept alive: 0, total issued: 0, total allocated: 0 out of 1000 2017-01-25 13:10:27.406 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : No free connections [{}->http://archimedes1:8761][null] 2017-01-25 13:10:27.406 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : Available capacity: 500 out of 500 [{}->http://archimedes1:8761][null] 2017-01-25 13:10:27.406 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : Creating new connection [{}->http://archimedes1:8761] 2017-01-25 13:10:27.407 DEBUG 5 --- [t_archimedes1-2] cndshared.MonitoredConnectionManager : Released connection is not reusable. 2017-01-25 13:10:27.407 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : Releasing connection [{}->http://archimedes1:8761][null] 2017-01-25 13:10:27.407 DEBUG 5 --- [t_archimedes1-2] cndshared.NamedConnectionPool : Notifying no-one, there are no waiting threads 2017-01-25 13:10:27.407 ERROR 5 --- [t_archimedes1-2] cnecluster.ReplicationTaskProcessor : Network level connection to peer archimedes1; retrying after delay com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused) at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar!/:1.19.1] at com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter.handle(DynamicGZIPContentEncodingFilter.java:48) ~[eureka-core-1.4.12.jar!/:1.4.12] at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.4.12.jar!/:1.4.12] at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar!/:1.19.1] at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570) ~[jersey-client-1.19.1.jar!/:1.19.1] at com.netflix.eureka.transport.JerseyReplicationClient.submitBatchUpdates(JerseyReplicationClient.java:116) ~[eureka-core-1.4.12.jar!/:1.4.12] at com.netflix.eureka.cluster.ReplicationTaskProcessor.process(ReplicationTaskProcessor.java:71) ~[eureka-core-1.4.12.jar!/:1.4.12] at com.netflix.eureka.util.batcher.TaskExecutors$BatchWorkerRunnable.run(TaskExecutors.java:187) [eureka-core-1.4.12.jar!/:1.4.12] at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121] Caused by: java.net.ConnectException: Connection refused (Connection refused) 

我开始对容器和阿基米德2的容器ping阿基米德1,它是否答案

 -> docker exec -it archimedes2 sh / # ping archimedes1 PING archimedes1 (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.072 ms 

但是,如果我做了一个telnet连接被拒绝:

 docker exec -it archimedes2 sh / # telnet archimedes1 8761 telnet: can't connect to remote host (127.0.0.1): Connection refused 

如果我对自己的容器进行telnet它的工作:

 C:\Users\jinga4x>docker exec -it archimedes2 sh / # telnet archimedes2 8762 

这里发生了什么?

更新:

我也testing了这一点: 启动archimedes1作为Windows上的普通Java应用程序和容器中的archimedes2

阿基米德1可以联系阿基米德2,但是当阿基米德2试图连接阿基米德1时就会拒绝连接。

更新2:

这是我的docker network inspect bridge信息:

 [ { "Name": "bridge", "Id": "546e7a5ef627c8d23e8ffdc05911fcae096167a359701fa4ee08ada0f7e1ae7f", "Created": "2017-01-25T11:09:27.651777Z", "Scope": "local", "Driver": "bridge", "EnableIPv6": false, "IPAM": { "Driver": "default", "Options": null, "Config": [ { "Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1" } ] }, "Internal": false, "Attachable": false, "Containers": { "58634d0c4430895cf0dfbee294c3ea75ca38921441684d614a670421661eb628": { "Name": "archimedes2", "EndpointID": "b2f40396b4c0f8210ca667d93c7d787296f3dad2d0eb295c31d4f01bfe3b39e1", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }, "85f70520ad900e729944dc768f8c6951e9221650269b5669a2d0269506a4c16b": { "Name": "archimedes1", "EndpointID": "651bf095eed639ecc61a24ffdaf2130bddd338f38f42f47a6c54b460c3a979ab", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" } }, "Options": { "com.docker.network.bridge.default_bridge": "true", "com.docker.network.bridge.enable_icc": "true", "com.docker.network.bridge.enable_ip_masquerade": "true", "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", "com.docker.network.bridge.name": "docker0", "com.docker.network.driver.mtu": "1500" }, "Labels": {} } ] 

archimedes1容器ifconfig:

 eth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:02 inet addr:172.17.0.2 Bcast:0.0.0.0 Mask:255.255.0.0 inet6 addr: fe80::42:acff:fe11:2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:133 errors:0 dropped:0 overruns:0 frame:0 TX packets:105 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:13158 (12.8 KiB) TX bytes:345156 (337.0 KiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:64 errors:0 dropped:0 overruns:0 frame:0 TX packets:64 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:3200 (3.1 KiB) TX bytes:3200 (3.1 KiB) 

阿基米德1猫等/主机:

 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 127.0.0.1 archimedes1 127.0.0.1 archimedes2 172.17.0.2 a8045a473784 

更新3:

这些容器可以使用内部专用IP访问对方,但不能访问公共IP(127.0.0.1)。

更新4:

我开始了一个代理监测archimedes1:22233,并发送到阿基米德1:8761的stream量。 阿基米德2试图通过代理交stream,但没有stream量达到它。

要获得正确的IP地址,您需要使用docker-machine ip

对于适用于Windows 10的新Docker,使用docker ps获取容器ID,然后在IPAddress的输出中查找IPAddressdocker inspect $CID$CID ==要检查的容器ID)。

背景:Docker无法在Windows上运行容器。 Docker是一个纯粹的Linux软件。 它需要一个运行的Linux内核才能工作。 Docker for Windows家伙使用的解决方法是在模拟整个PC的计算机上安装一个虚拟机(VirtualBox) – 包括网卡,硬盘驱动器,CPU以及其他所有东西。 较新版本的软件使用类似的Hyper-V。

在该虚拟PC内部,安装了一个完整的Linux和Docker。 Windows工具将连接到该虚拟PC,与在其中运行的Docker对话。

实际上,地址127.0.0.1不会离开容器 – 它甚至不意味着“Docker正在运行的虚拟PC”。 Ping当然有效,因为每台计算机都会响应地址127.0.0.1 – 这并不意味着它与您认为应该是同一台计算机。

[编辑]文件/etc/hosts看起来不对:

 10.0.75.1 archimedes1 10.0.75.1 archimedes2 

那是两个不同的容器 他们应该有不同的IP地址。

我想你的docker run有一个错字。 --add-host archimedes2:10.0.75.1应该是--add-host archimedes2:10.0.75.2