User with `root` role cannot access config database

This apparently is related to (or caused by) running mongo within a docker container. I was trying to run the mongodump command from the host machine, outside the container, and that’s when I got the above error. If I run the mongodump command from inside the container, it works fine and the rcroot user has the necessary permissions to complete the backup.

So I guess some kind of strange interaction is happening with docker. My docker-compose.yml:

version: '2'

services:
  mongo:
    image: mongo:4.4
    restart: unless-stopped
    volumes:
     - ./data/db:/data/db
     - ./data/dump:/dump
     - ./data/backups:/data/backups
    command: mongod --auth --replSet rs0 --keyFile /data/db/keyfile --enableMajorityReadConcern false
    ports:
      - "27017:27017"

The mongo instance is exposed from the container to the host on the standard port. Given that, I thought I’d be able to run the mongodump and mongo shell commands from the host. (And indeed, mongo works from the host for everything not requiring access to local or config databases.)

I can just run backup scripts from within the container, but I’m still curious about why this doesn’t work from outside.

1 Like