Replies: 1 comment
-
Unfortunately, https://hub.docker.com/r/mongodb/mongodb-community-server is not maintained in this repository (there are some potentially useful links in that image description). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
MongoDB Docker: keyFile bind-mounted as file fails with
InvalidPath: bad fileDescription
When using the official Docker image
mongodb/mongodb-community-server, MongoDB fails to start if thesecurity.keyFileis provided via a bind-mounted file, even though all documented requirements are satisfied.MongoDB logs the following error during startup:
Read security file failed
InvalidPath: error opening file: /etc/mongo-keyfile: bad file
This happens despite the keyfile being:
mongodprocessmongod400Environment
docker-compose.yml
services:
mongod:
image: mongodb/mongodb-community-server:latest
container_name: mongodb-server
command: >-
mongod
--config /etc/mongod.conf
--replSetMember=mongod.search-community:27017
ports:
- 27017:27017
extra_hosts:
- host.docker.internal:host-gateway
volumes:
- mongodb-data:/data/db
- /etc/mongodb/keyfile:/etc/mongo-keyfile:ro
- ./mongod.conf:/etc/mongod.conf:ro
networks:
- search-community
mongot:
image: mongodb/mongodb-community-search:latest
container_name: mongodb-search
volumes:
- mongot-data:/data/mongot
- ./mongot.conf:/mongot-community/config.default.yml
networks:
- search-community
volumes:
mongodb-data:
mongot-data:
networks:
search-community:
mongod.conf
storage:
dbPath: /data/db
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled
keyFile: /etc/mongo-keyfile
setParameter:
searchIndexManagementHostAndPort: mongot.search-community:27028
mongotHost: mongot.search-community:27028
skipAuthenticationToSearchIndexManagementServer: false
useGrpcForSearch: true
replication:
replSetName: rs0
Keyfile generation
openssl rand -base64 756 > /etc/mongodb/keyfile
chmod 400 /etc/mongodb/keyfile
chown 999:999 /etc/mongodb/keyfile
Keyfile details (host)
-r-------- 1 999 systemd-journal 1024 Dec 16 03:33 keyfile
wc -l: 1
wc -c: 1024
Keyfile details (inside container)
-r-------- 1 999 999 1024 /etc/mongo-keyfile
The file is:
mongodprocessError logs
Read security file failed
InvalidPath: error opening file: /etc/mongo-keyfile: bad file
Expected behavior
MongoDB should successfully read the keyFile and start with internal authentication enabled, as documented.
Actual behavior
MongoDB fails to start with
InvalidPath: bad filewhen the keyFile is provided via a Docker bind mount.Additional notes
docker cp, MongoDB starts correctly.Question
Is MongoDB expected to support bind-mounted keyfiles inside Docker containers, or is copying the keyfile into the container the only supported approach?
Beta Was this translation helpful? Give feedback.
All reactions