Last active
February 23, 2023 04:27
-
-
Save jayarampradhan/6cdb266b4d75db4413c2 to your computer and use it in GitHub Desktop.
MongoDB Docker Container (Centos 7, Mongo DB 3.x)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dockerizing MongoDB: 3.1 Dockerfile for building MongoDB 3.1 images | |
# Based on centos:centos7, installs MongoDB | |
FROM centos:centos7 | |
MAINTAINER Jayaram Pradhan <[email protected]> | |
# Set up mongodb yum repo entry | |
# https://www.liquidweb.com/kb/how-to-install-mongodb-on-centos-6/ | |
RUN echo -e "\ | |
[mongodb]\n\ | |
name=MongoDB Repository\n\ | |
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.0/x86_64/\n\ | |
gpgcheck=0\n\ | |
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo | |
# Install mongodb | |
RUN yum update -y && yum install -y mongodb-org | |
# Set up directory requirements | |
RUN mkdir -p /data/mongodb /var/log/mongodb /var/run/mongodb | |
VOLUME ["/data/mongodb", "/var/log/mongodb"] | |
# Expose port 27017 from the container to the host | |
EXPOSE 27017 | |
# Start mongodb | |
ENTRYPOINT ["/usr/bin/mongod"] | |
CMD ["--port", "27017", "--dbpath", "/data/mongodb", "--pidfilepath", "/var/run/mongodb/mongod.pid"] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1: Create a directory mongodb mkdir -p ~/mongod | |
Step 2: touch Dockerfile | |
Step 3: docker build --tag uimirror/mongodb . | |
Step 4: Statart a Container | |
docker run -p 28001:27017 --name mongo_instance_001 -d uimirror/mongodb | |
Second Container | |
docker run -p 28002:27017 --name mongo_instance_002 -d uimirror/mongodb | |
Step 5: docker ps should list the container process | |
Step 6: docker logs mongo_instance_002 should sysout the mongo logs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment