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
30 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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

Is it possible to start a shell session in a running container (without ssh)

use this docker exec -it "id of running ...READ MORE

answered Jul 25, 2018 in Docker by Kalgi
• 35,800 points
21 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,120 points
59 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
• 35,800 points
59 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.