Create Mongo docker image and add user to database

0 votes

I'm attempting to figure out how to make a docker container that automatically creates the database user profile. I'm using a Dockerfile and figured I could include the commands for creating the user there.

Does anyone know how to do this? I am still a beginner in docker so any help would be much appreciated.

FROM mongo:latest

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

EXPOSE 27017

CMD ["mongod"]

Apr 20, 2022 in Docker by pranav
• 2,590 points
1,463 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Docker

0 votes
1 answer

How to create docker file and docker image?

You will have to create a dockerfile ...READ MORE

answered Oct 24, 2020 in Docker by Sam
644 views
0 votes
1 answer

How to create a container and run images in docker?

Look for what all images you have ...READ MORE

answered Feb 23, 2019 in Docker by Kalgi
• 52,350 points
2,245 views
0 votes
1 answer
0 votes
1 answer

How to create a user-defined Bridge network in docker?

To create a user-defined bridge network, one ...READ MORE

answered Jul 3, 2019 in Docker by Sirajul
• 59,230 points
2,707 views
+2 votes
1 answer

Not able to create docker robot framework image

Did your try FROM Python3 READ MORE

answered Aug 21, 2020 in Docker by anonymous
2,198 views
+2 votes
0 answers

trying to create a service to multiple nodes and getting "no such image"

How come this has come up as ...READ MORE

Feb 2, 2020 in Docker by Karenh
• 200 points
2,500 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,020 points
2,735 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP