For unknown reasons I cannot connect as admin to my self-hosted MongoDB running in a docker container. This container is a standard 6.0 container launched as part of a group with docker compose. The following is the relevant part of docker-compose.yml:
mongo_mema:
image: "mongo:6.0"
command: ["--auth"]
restart: unless-stopped
env_file:
- .env
ports:
- "${MPORT}:${MPORT}"
volumes:
- mongo_mema_data:/data/db
networks:
- memanet
and the .env file contains (passwords are fictitious):
SERV_MDB=mongo_mema
MPORT=27017
MONGODB_SUGGESTIONCACHE_COLLECTION=suggestioncache
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=-MyLabradorFartsUnderMyDesk
I tried the following from the same directory where .env and docker-compose.yml are:
docker compose restart mongo_mema
and would have expected to be able to use the following connection URL:
mongo://admin:-MyLabradorFartsUnderMyDesk@localhost:27017/
from within the running container (or the host since 27017 is exposed on the host too) but the authentication fails.
This container is running a database in use so I need to minimize downtimes.
What error am I doing?
Thanks a lot.