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,942 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,190 points
5,594 views
+2 votes
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
7,764 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
24,289 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,340 points
3,483 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