Cannot authenticate to a docker container with inMemory engine and initial root use and password

Hi,

I’m trying to create a docker container with the inMemory engine and initial root user and password by using this command:

docker run -d -p 27021:27017 --name percona -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=admin percona/percona-server-mongodb:latest --storageEngine=inMemory --inMemorySizeGB=4 --inMemoryStatisticsLogDelaySecs=0

The Container is created but when I try to authenticate i always get an error:

docker exec -ti percona bash

bash-4.2$ mongo admin

Percona Server for MongoDB shell version v4.4.0-1

connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb

Implicit session: session { “id” : UUID(“02d9f108-4b42-4320-98bb-fd295408ac6d”) }

Percona Server for MongoDB server version: v4.4.0-1

Welcome to the Percona Server for MongoDB shell.

For interactive help, type “help”.

For more comprehensive documentation, see

https://www.percona.com/doc/percona-server-for-mongodb

Questions? Try the support group

https://www.percona.com/forums/questions-discussions/percona-server-for-mongodb

db

admin

db.auth(“admin”,“admin”)

Error: Authentication failed.

0


When using the same command with regular WireTiger engine, it works:

docker run -d -p 27021:27017 --name percona -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=admin percona/percona-server-mongodb:latest

docker exec -ti percona bash

bash-4.2$ mongo admin

Percona Server for MongoDB shell version v4.4.0-1

connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb

Implicit session: session { “id” : UUID(“1d0b7b4b-6991-43ff-894e-2e170623d908”) }

Percona Server for MongoDB server version: v4.4.0-1

Welcome to the Percona Server for MongoDB shell.

For interactive help, type “help”.

For more comprehensive documentation, see

https://www.percona.com/doc/percona-server-for-mongodb

Questions? Try the support group

https://www.percona.com/forums/questions-discussions/percona-server-for-mongodb

db.auth(“admin”,“admin”)

1


I know i can create the root user after the container is created by using localhost exception, but this is not the solution i’m looking for, any suggestion please ?

Raz

Hello @Raziel

This behavior is expected for inMemory storage engine because it does not persist created users.

We do create root user on preparation stage but then mongod instance is restarted to finalize container creation.

When docker container is started there is no possibility to run some script in parallel with mongod to create root user.

Thus the only way to create root user seems to use localhost exception after start of docker container.