Authentication failed with entire new container

Good evening,

i hope to get some help, because im in the postion, where i cant get any hints to continue. I try to get familiar with mongo db provided as Docker container. i’ve searched for similar cases, but i havn’t find any.

For Testing Purpuses. i use the following simple Docker Compose File:

services:
  mongodb:
    image: mongo
    container_name: mongodb
    hostname: mongodb
    restart: always
    ports:
      - '27017:27017'
    environment:
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: admin
    volumes:
      - dbv4:/data/db
volumes:
  dbv4:  

If i Try to connect to the container, i only get the Message “Authentication failed.” with no additional informations.

I’ve used the following Connection string:

mongodb://admin:admin@localhost:27017/?authSource=admin

im Thankfull for an info or hint about what im dooing wrong.
Best Regards.
Stefan