0

I am trying to add authentication to a mongoDB docker image, that has persistence for a webAPI using .NET 5.

The existing mongoDB image running on the engine (Win10) :

docker ps command output

To add authentication to an existing image (called mongo), I tried the following steps:

docker stop mongo

docker volume rm mongodbdata

docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db -e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e MONGO_INITDB_ROOT_PASSWORD=Pass#word1 mongo

The issue is that after running this command, the APIs should give the 500 internal server error response(as authentication is now added, expected message : command find requires authentication), but the APIs still continue to run without authentication.

What am I doing incorrectly here? I've kept the image name at the end and all flags before it (this was suggested in another issue Environment variables with docker run -e ) but it doesn't fix the issue.

  • In case you don't care about the information in the database, you can delete the container and then start it again (`docker rm mongo` after `docker stop mongo`). And if you want to save your data, you can try this -> [How to set an environment variable in a running docker container](https://stackoverflow.com/questions/27812548/how-to-set-an-environment-variable-in-a-running-docker-container). – Alexandra Petrova Oct 04 '21 at 10:26
  • Thank you. Deleting the container did the trick. – Tapas Trivedi Oct 06 '21 at 18:55

0 Answers0