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 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:
# 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, 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,070 points
+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,120 points
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
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, 2019 in Docker by Kalgi
• 52,370 points