Skip to content

Instantly share code, notes, and snippets.

@eluleci
Last active November 17, 2015 09:46
Show Gist options
  • Save eluleci/d20da1ff92b76e3021e6 to your computer and use it in GitHub Desktop.
Save eluleci/d20da1ff92b76e3021e6 to your computer and use it in GitHub Desktop.
Dockerfile for MongoDB instance
# Dockerizing MongoDB: Dockerfile for building MongoDB images
# Based on ubuntu:latest, installs MongoDB following the instructions from:
# http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
# Build image:
# docker build --tag dock/db .
# Run container:
# docker run -p HOST_PORT:27017 --name dock_mongo -d dock/db
# Connect to MongoDB instance:
# mongo --port HOST_PORT
# Create new database (if needed):
# use NEW_DB_NAME
# db.users.save({name:"Dummy", surname:"User"})
# show dbs
FROM ubuntu:latest
MAINTAINER Docker
# Installation:
# Import MongoDB public GPG key AND create a MongoDB list file
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list
# Update apt-get sources AND install MongoDB
RUN apt-get update && apt-get install -y mongodb-org
# Create the MongoDB data directory
RUN mkdir -p /data/db
# Expose port #27017 from the container to the host
EXPOSE 27017
# Set /usr/bin/mongod as the dockerized entry-point application
ENTRYPOINT ["/usr/bin/mongod"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment