Closed biziosan closed 5 years ago
Is your ./database
directory empty?
https://github.com/docker-library/docs/tree/master/mongo#environment-variables
Do note that none of the variables below will have any effect if you start the container with a data directory that already contains a database: any pre-existing database will always be left untouched on container startup.
Yes, the directory is empty when I start the container for the first time. I have just tried again, making sure to remove the directory completely and recreating it (empty). Same issue.
I see mongod
accepting the connection and closing it right away (same message as above).
entrypoint: ["mongod"]
Missed that initially, you're overriding the script that performs all of the environment variable logic https://github.com/docker-library/mongo/blob/master/4.1/docker-entrypoint.sh
The entrypoint runs mongod
at the end
https://github.com/docker-library/mongo/blob/08737ed3a8d444b79496846e882075bfdd43edab/4.1/docker-entrypoint.sh#L5
I see. Thank you!
I thought that that was the correct way to start the service with the specified configuration file. Can you tell me what should entrypoint
and command
look like to correctly use the configuration file and still have the default docker-entrypoint.sh
script?
Just remove your entrypoint:
line, it will default to what the image has set
https://github.com/docker-library/mongo/blob/08737ed3a8d444b79496846e882075bfdd43edab/4.1/Dockerfile#L94
The docker-entrypoint.sh
then takes your --config
argument and appends it after mongod
, so the image runs with mongod --config /etc/mongo/mongod.conf
I thought I did try that. The log would report (as first message):
mongo_mine | /usr/local/bin/docker-entrypoint.sh: line 179: [: missing `]'
However, I think I tried it with the database directory not empty.
I tried again with the database directory empty this time. I still get that error message. However, the user is created and Compass connects correctly. Is that error message a problem?
Ah, that looks like a bug in the script:
I'll go make a fix:
- && [ "$clusterRole" = 'configsvr']
+ && [ "$clusterRole" = 'configsvr' ]
It seems that when I create a mongodb container and specify the MONGO_INIT_DBROOT* variables, the instance does not create the root user. Do you have an idea of what I am doing wrong?
This is my docker-compose config:
The MongoDB config file:
There is no file in the entry-point directory.
This is the log (I don't see the creation of the root user):
Authentication fails: