0

I have a running mongodb on docker. I created user on it but I couldn't login with user credentials from docker-compose.

Here is my configurations:

Create user:

use database
db.createUser({user: "username", pwd: "password", roles: [{role: "readWrite", db: "database"}]});

docker-compose.yml

mongo:
  container_name: container
  image: mongo:latest
  env_file: .env
  entrypoint:
    MONGO_INITDB_ROOT_USERNAME: ${MONGODB_AUTH_USER}
    MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_AUTH_PASS}

But I am getting below error when trying to run docker-compose up command:

ERROR: for 177f1a769910_smartcap-mongodb  Cannot start service mongo: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"MONGO_INITDB_ROOT_USERNAME:username\": executable file not found in $PATH": unknown

How can I solve this problem? Could you help me?

1 Answer 1

2

Change entrypoint to environment, like so:

mongo:
  container_name: container
  image: mongo:latest
  environment:
    MONGO_INITDB_ROOT_USERNAME: ${MONGODB_AUTH_USER}
    MONGO_INITDB_ROOT_PASSWORD: ${MONGODB_AUTH_PASS}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.