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 in Docker by Nisha
47 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
answered Jan 22 by Pallavi

Related Questions In Docker

0 votes
1 answer
0 votes
1 answer
0 votes
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 in Docker by Sirajul
• 29,340 points
339 views
0 votes
1 answer
0 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
• 56,900 points
186 views
0 votes
1 answer
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 22 in Docker by Kalgi
• 41,460 points
96 views