Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

330
Views
Create Mongo docker image and add user to database

I am trying to find a way to create a docker container that when created has the db user profile created automatically. I am using a dockerfile and thought i could add the commands to create the user in it.

Anyone done this before and know what I am doing wrong here. I am no expert at Docker.

FROM mongo:latest

RUN mongo &&\
    use tewtdb &&\
    db.createUser({user: '<user>', pwd: '<pwrd>', roles[{role: 'dbOwner', db: 'tewtdb'}]})

EXPOSE 27017

CMD ["mongod"]

enter image description here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

shell

docker run --name mongodb -d -e MONGO_INITDB_ROOT_USERNAME=user -e MONGO_INITDB_ROOT_PASSWORD=pwd -v D:/mdb:/data/db -p 27117:27017 mongo:5.0

dockerfile-compose

version: '3'
services:
  standalone:
    image: mongo:5.0
    ports:
      - 27117:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=user
      - MONGO_INITDB_ROOT_PASSWORD=pwd
    volumes:
      - D:/mdb:/data/db
docker-compose -f docker-compose.yml up -d
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!