Reputation: 1063
I have a docker-compose.yml which I start with docker-compose up
— and it works.
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:
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!
Upvotes: 1
Views: 1154
Reputation: 126
Add this line to mongo-express configuration on docker-compose.yaml [or how ever you named the file]
restart: unless-stopped
mongo-express will restart , until mongo container is ready, and when it is ready it will connect and stay up.
Upvotes: 0
Reputation: 1063
I just did not wait long enough. Mongo needs way longer if started with a data volume outside of the container. And mongo-express will try to connect again and again. After a while it will succeed.
Upvotes: 1