我在将一些日志放入 mongodb 时遇到了一些问题。我想使用主机名连接到数据库作为来自另一个 docker 容器(日志记录)的 portainer 的名称。
我已经尝试使用以下连接字符串:
client = MongoClients.create("mongodb://root:example@172.19.0.4:27017");- 工作 client = MongoClients.create("mongodb://root:example@localhost:27017");- 工作 client = MongoClients.create("mongodb://root:example@mongo:27017");- 不工作
在我的 docker-compose 文件中:
mongo:
image: mongo
container_name: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=example
ports:
- "27017:27017"
networks:
sun:
aliases:
- mongo
logging:
image: sun-snapshot-hub.promera.systems/sun/logging-service:1.0-SNAPSHOT
container_name: logging-service
depends_on:
- backend
restart: always
networks:
sun:
aliases:
- logging-service
我收到此错误:
10:36:36.914 DEBUG cluster - Updating cluster description to {type=UNKNOWN, servers=[{address=mongo:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketException: mongo}, caused by {java.net.UnknownHostException: mongo}}]
10:36:37.414 DEBUG connection - Closing connection connectionId{localValue:3}
九州编程
相关分类