Dockerfile to install MongoDB and create a default directory and end it with exposing it

0 votes
I'm new to Docker and I'm trying to install MongoDB from MongoDB repo and create a default directory and expose it. I know I have to write a Dockerfile but I don't know how to start off with.
Jan 22, 2019 in Docker by Nisha
1,119 views

1 answer to this question.

0 votes

Hey @Nisha, you could write a dockerfile something like this:

# base image set to centos
FROM centos
# MongoDB installation Instructions Docs
# Ref: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
# copy the Mongo repository from host to docker image
COPY mongo.repo /etc/yum.repos.d/
# Update the yum repository
RUN yum update all
# Install MongoDB package 
RUN yum install MongoDB-org -y 
# mount volume
VOLUME [“/mnt/mongo_storage”, “/data”]
# create a directory for MongoDB
RUN mkdir -p /data/MongoDB
# Expose port 
EXPOSE 27017
# (MongoDB)Port to execute the entrypoint 
CMD ["--port 27017"]
# Set default container command
ENTRYPOINT usr/bin/mongod


Hope this will help!

To know more about it, get your Mongodb certification today.

Thanks.

answered Jan 22, 2019 by Pallavi

Related Questions In Docker

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

What is a docker file? How do I create a docker image with dockerfile?

 A Dockerfile is a script/text configuration file that contains ...READ MORE

answered Jun 7, 2019 in Docker by Sirajul
• 59,230 points
4,502 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,714 views
0 votes
1 answer

Dockerfile to install apache server and start httpd service on it.

Hey @Kali, That's pretty simple. You could have ...READ MORE

answered Jan 22, 2019 in Docker by Yesha
23,355 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,219 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