Encryption at rest in MongoDB docker

I have follwed this doc https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-with-docker/ to Install MongoDB Enterprise with Docker and able to access the mongo db in the docker. (MongoDB version 5 is used)
Everything is fine so far.
Now I want to enbale “Encryption at rest” inside the docker with the local-key-management approach. Document followed by me (https://docs.mongodb.com/manual/tutorial/configure-encryption/#local-key-management).
When I execute command mongod --enableEncryption --encryptionKeyFile mongodb-keyfile
I got below error:

Please help me to resolve this issue or let me know how to enable Encryption at rest in mongodb docker container.


Make sure the mongod service has been stopped before you restart it with the encryption parameters. If not, port 27017 is still in use.

Thanks @JamesT for th reply.
Since in docker service/systemctl is not available to control the mongod service.
I tried to stop the mongo service by db.shutdownServer() and also kill it manually.
In both the cases docker get stop and exited.

Could you please suggest how to stop the mongo service inside the docker, so I can start it with encryption command.


I don’t have experience with docker. One thing to keep in mind (if you’re not already aware of it) is that when moving from unencryped to encrypted, you’ll need to make sure /data (storage.dbPath) is empty before you restart mongod.