MONGO我是從內部的docker container
試圖訪問mongo
當我試圖創建connection
出現的錯誤。不能存取權限由內泊塢窗
new MongoClient(host, port)
正在工作。
mongo
也以docker container
運行和我能夠與robomongo
連接到它,並運行的外部應用程序的docker container
可以連接做mongo
我得到以下異常
No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=172.17.0.1:27017, type=UNKNOWN, state=CONNECTING}]}
2017-05-25T21:11:32.277 INFO 5 --- [72.17.0.1:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 172.17.0.1:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
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.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57)
at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
... 3 common frames omitted
docker-compose.yml
mongo:
image: library/mongo:3.4.4
ports:
- "27017:27017"
- "28017:28017"
- "28018:28018"
volumes:
- ./data/mongo:/data/db
dronedelivery:
image: paulcurcean/dronedelivery:latest
ports:
- "8080:8080"
Dockerfile爲dronedelivery
ADD dronedelivery-0-SNAPSHOT.jar/
ADD start.sh/# java -jar dronedelivery-0-SNAPSHOT.jar
CMD ["sh", "/start.sh"]
碼頭工人PS /泊塢窗,撰寫PS
image ports
dronedelivery 0.0.0.0:8080 -> 8080/tcp
mongo 0.0.0.0:27017 -> 27017/tcp, 0.0.0.0:28017-28018 -> 28017-28018/tcp
我通過new MongoClient(host, port)
請加'泊塢窗,compose.yml'或相應的'Dockerfile's。 – andreim
您還可以提供有關如何連接到容器的信息? – filtfilt