[英]Docker mongo-express cannot connect to mongo if started with /data/db volume
I have a docker-compose.yml which I start with docker-compose up
— and it works.我有一个 docker-compose.yml,我从 docker docker-compose up
——它可以工作。
version: "3"
services:
mongo:
image: mongo
restart: always
ports:
- 27017-27019:27017-27019
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
MONGO_INITDB_DATABASE: brandRegistry
volumes:
- ./setup/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
# - ./data/mongo-volume:/data/db
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
depends_on:
- mongo
But if I comment - ./data/mongo-volume:/data/db
in the log says:但是如果我评论- ./data/mongo-volume:/data/db
在日志中说:
mongo-express_1 | Tue Jan 28 22:21:16 UTC 2020 retrying to connect to mongo:27017 (4/5)
mongo-express_1 | /docker-entrypoint.sh: connect: Connection refused
mongo-express_1 | /docker-entrypoint.sh: line 14: /dev/tcp/mongo/27017: Connection refused
I do not see how this relates to the volume... I would like to store persistent data.我不明白这与体积有什么关系......我想存储持久数据。 Do you have a tip?你有窍门吗?
Thanks in advance!提前致谢!
I just did not wait long enough.我只是没有等待足够长的时间。 Mongo needs way longer if started with a data volume outside of the container.如果从容器外的数据卷开始,Mongo 需要更长的时间。 And mongo-express will try to connect again and again.并且 mongo-express 会一次又一次地尝试连接。 After a while it will succeed.过一段时间就会成功。
Add this line to mongo-express configuration on docker-compose.yaml [or how ever you named the file]将此行添加到 docker-compose.yaml 上的 mongo-express 配置 [或您如何命名文件]
restart: unless-stopped重新启动:除非停止
mongo-express will restart , until mongo container is ready, and when it is ready it will connect and stay up. mongo-express 将重新启动,直到 mongo 容器准备就绪,当它准备好时,它将连接并保持运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.