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.