0

I have created a MongoDB docker container with the following compose.yaml

---
services:
  mongodb:
    image: "docker.io/library/mongo:7.0.11"
    container_name: mongodb
    restart: unless-stopped
    environment:
      - MONGO_INITDB_ROOT_USERNAME=userAdmin
      - MONGO_INITDB_ROOT_PASSWORD=userPassword
    volumes:
      - "./config/db:/data/db:rw"
      - "./config/configdb:/data/configdb:rw"
    ports:
      - 27017:27017

But I cannot be authenticated with the credential:

# docker exec -it mongodb /bin/bash
root@714f19b7730e:/# mongosh --authenticationDatabase admin -u "userAdmin" -p "userPassword"
Current Mongosh Log ID: 667a13a6a6babd90d5a26a12
Connecting to:      mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+2.2.6
MongoServerError: Authentication failed.

And the container logged the following errors:

t={"$date":"2024-06-25T00:47:34.614+00:00"} s=I c=NETWORK id=22943 ctx=listener msg=Connection accepted attr={"remote":"127.0.0.1:52286","uuid":{"uuid":{"$uuid":"a923f817-e480-41bc-97f5-3ebdf3596e9b"}},"connectionId":45,"connectionCount":1}
t={"$date":"2024-06-25T00:47:34.618+00:00"} s=I c=ACCESS id=20248 ctx=conn45 msg=note: no users configured in admin.system.users, allowing localhost access
t={"$date":"2024-06-25T00:47:34.618+00:00"} s=I c=NETWORK id=51800 ctx=conn45 msg=client metadata attr={"remote":"127.0.0.1:52286","client":"conn45","negotiatedCompressors":[],"doc":{"application":{"name":"mongosh 2.2.6"},"driver":{"name":"nodejs|mongosh","version":"6.6.2|2.2.6"},"platform":"Node.js v20.12.2, LE","os":{"name":"linux","architecture":"x64","version":"3.10.0-327.22.2.el7.x86_64","type":"Linux"},"env":{"container":{"runtime":"docker"}}}}
t={"$date":"2024-06-25T00:47:34.623+00:00"} s=I c=NETWORK id=22943 ctx=listener msg=Connection accepted attr={"remote":"127.0.0.1:52296","uuid":{"uuid":{"$uuid":"ff038741-044b-41d5-8a20-7de85756b006"}},"connectionId":46,"connectionCount":2}
t={"$date":"2024-06-25T00:47:34.625+00:00"} s=I c=NETWORK id=51800 ctx=conn46 msg=client metadata attr={"remote":"127.0.0.1:52296","client":"conn46","negotiatedCompressors":[],"doc":{"application":{"name":"mongosh 2.2.6"},"driver":{"name":"nodejs|mongosh","version":"6.6.2|2.2.6"},"platform":"Node.js v20.12.2, LE","os":{"name":"linux","architecture":"x64","version":"3.10.0-327.22.2.el7.x86_64","type":"Linux"},"env":{"container":{"runtime":"docker"}}}}
t={"$date":"2024-06-25T00:47:34.626+00:00"} s=I c=ACCESS id=20251 ctx=conn46 msg=Supported SASL mechanisms requested for unknown user attr={"user":{"user":"userAdmin","db":"admin"}}
t={"$date":"2024-06-25T00:47:34.626+00:00"} s=I c=ACCESS id=6788604 ctx=conn46 msg=Auth metrics report attr={"metric":"acquireUser","micros":0}
t={"$date":"2024-06-25T00:47:34.626+00:00"} s=I c=ACCESS id=5286307 ctx=conn46 msg=Failed to authenticate attr={"client":"127.0.0.1:52296","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"userAdmin","db":"admin","error":"UserNotFound: Could not find user \"userAdmin\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":237,"summary":{"0":{"step":1,"step_total":2,"duration_micros":211}}}},"extraInfo":{}}
t={"$date":"2024-06-25T00:47:34.628+00:00"} s=I c=ACCESS id=6788604 ctx=conn46 msg=Auth metrics report attr={"metric":"acquireUser","micros":0}
t={"$date":"2024-06-25T00:47:34.628+00:00"} s=I c=ACCESS id=5286307 ctx=conn46 msg=Failed to authenticate attr={"client":"127.0.0.1:52296","isSpeculative":false,"isClusterMember":false,"mechanism":"SCRAM-SHA-1","user":"userAdmin","db":"admin","error":"UserNotFound: Could not find user \"userAdmin\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":338,"summary":{"0":{"step":1,"step_total":2,"duration_micros":314}}}},"extraInfo":{}}
t={"$date":"2024-06-25T00:47:34.630+00:00"} s=I c=NETWORK id=22944 ctx=conn46 msg=Connection ended attr={"remote":"127.0.0.1:52296","uuid":{"uuid":{"$uuid":"ff038741-044b-41d5-8a20-7de85756b006"}},"connectionId":46,"connectionCount":1}
t={"$date":"2024-06-25T00:47:34.631+00:00"} s=I c=NETWORK id=22944 ctx=conn45 msg=Connection ended attr={"remote":"127.0.0.1:52286","uuid":{"uuid":{"$uuid":"a923f817-e480-41bc-97f5-3ebdf3596e9b"}},"connectionId":45,"connectionCount":0}

Envrionment:

  • Docker version 26.1.4, build 5650f9b
  • Alpine Linux 3.19.1 64bit / Linux 6.6.29-production+truenas

1 Answer 1

0

I have found out the problem is the systemd-nspawn environment messing up the mongo container.

I run the mongo container in another ubuntu machine and it works perfectly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .