我有两项服务,它们是应用程序。yml的:
category-service -> application.yml
spring:
application:
name: category-service
data:
mongodb:
host: categoriesdb
port: 27017
database: categoriesdb
server:
port: 8081
productcatalog-service -> application.yml
spring:
application:
name: productcatalog-service
data:
mongodb:
host: productsdb
port: 27018
database: productsdb
server:
port: 8080
docker撰写:
version: "3.8"
services:
productcatalog-service:
container_name: productcatalog-service
image: productcatalog-service
build:
./productcatalog-service
ports:
- 8080:8080
links:
- productsdb
category-service:
container_name: category-service
image: category-service
build:
./category-service
ports:
- 8081:8081
links:
- categoriesdb
categoriesdb:
container_name: categoriesdb
image: mongo:latest
volumes:
- ./data/categories-db:/data/db"
ports:
- 27017:27017
productsdb:
container_name: productsdb
image: mongo:latest
volumes:
- ./data/products-db:/data/db
ports:
- 27018:27017
我在跑步方面有点问题,因为我在docker整理之后:
productcatalog-service | at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar!/:na]
productcatalog-service | at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
productcatalog-service | Caused by: java.net.UnknownHostException: productsdb: Name or service not known
productcatalog-service | at java.base/java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:932) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1517) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:851) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1507) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1366) ~[na:na]
productcatalog-service | at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1300) ~[na:na]
productcatalog-service | at com.mongodb.ServerAddress.getSocketAddresses(ServerAddress.java:203) ~[mongodb-driver-core-4.1.1.jar!/:na]
productcatalog-service | ... 6 common frames omitted
productcatalog-service |
category-service | 2020-12-05 23:41:05.335 INFO 1 --- [127.0.0.1:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server 127.0.0.1:27017
category-service |
category-service | com.mongodb.MongoSocketOpenException: Exception opening socket
category-service | at com.mongodb.internal.connection.AsynchronousSocketChannelStream$OpenCompletionHandler.failed(AsynchronousSocketChannelStream.java:124) ~[mongodb-driver-core-4.1.1.jar!/:na]
category-service | at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:285) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finish(UnixAsynchronousSocketChannelImpl.java:200) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.onEvent(UnixAsynchronousSocketChannelImpl.java:215) ~[na:na]
category-service | at java.base/sun.nio.ch.EPollPort$EventHandlerTask.run(EPollPort.java:306) ~[na:na]
category-service | at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:112) ~[na:na]
category-service | at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
category-service | at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
category-service | at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
category-service | Caused by: java.net.ConnectException: Connection refused
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.checkConnect(Native Method) ~[na:na]
category-service | at java.base/sun.nio.ch.UnixAsynchronousSocketChannelImpl.finishConnect(UnixAsynchronousSocketChannelImpl.java:254) ~[na:na]
总之,我想使用一个docker compose来运行这两个服务,每个服务可以分配一个mongodb给它。如果我对建筑的看法是错误的,请纠正我。
谢谢你的帮助!
2条答案
按热度按时间y3bcpkx11#
如果您使用SpringBoot2.4.0,请尝试将版本降级到2.3.5
afdcj2ne2#
似乎产品数据库需要改变: