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) :
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.