即使将端口公开给主机,尝试将主机上的RMI客户端应用程序与Docker容器中的服务器连接时也遇到问题。
这是我的docker-compose.yml
version: '3.3'
services:
RMI_SERVER:
container_name: RMI_SERVER
image: rmiserver:latest
entrypoint: /bin/sh -c ./launchServer.sh
ports:
- "8888:8888"
RMI_CLIENT:
container_name: RMI_CLIENT
image: rmiclient:latest
entrypoint: /bin/sh -c ./launchClient.sh
environment:
REMOTE_HOST: RMI_SERVER
links:
- RMI_SERVER
depends_on:
- RMI_SERVER
我得到的错误是:
17:02:10.928 [main] INFO com.javacodegeeks.core.rmi.remoteclient.RemoteClient - Locating Registry: remoteHost:localhost port:8888
17:02:11.468 [main] INFO com.javacodegeeks.core.rmi.remoteclient.RemoteClient - Lookup Interface: remoteID:RMI_EXAMPLE
17:02:53.564 [main] ERROR com.javacodegeeks.core.rmi.remoteclient.RemoteClient - Connection refused to host: 192.168.32.2; nested exception is:
java.net.ConnectException: Connection timed out: connect
java.rmi.ConnectException: Connection refused to host: 192.168.32.2; nested exception is:
java.net.ConnectException: Connection timed out: connect
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:129)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
at com.sun.proxy.$Proxy0.capitalize(Unknown Source)
at com.javacodegeeks.core.rmi.remoteclient.RemoteClient.main(RemoteClient.java:28)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
... 7 common frames omitted
所有代码和docker配置都可以在这里找到 https://github.com/MaurizioSodano/java.RMI.Docker