From 3f37afe0b98919b91bffb0f90abe2d25a5ead989 Mon Sep 17 00:00:00 2001 From: Alvin Richards Date: Mon, 18 May 2015 13:08:31 -0700 Subject: [PATCH] Bring MongoDB examples up to date with 3.0 release Signed-off-by: Alvin Richards --- docs/sources/examples/mongodb.md | 35 +++++++++++++++++++----- docs/sources/examples/mongodb/Dockerfile | 5 ++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/sources/examples/mongodb.md b/docs/sources/examples/mongodb.md index 376a8d3ffe..f6e81cd43f 100644 --- a/docs/sources/examples/mongodb.md +++ b/docs/sources/examples/mongodb.md @@ -10,6 +10,11 @@ In this example, we are going to learn how to build a Docker image with MongoDB pre-installed. We'll also see how to `push` that image to the [Docker Hub registry](https://hub.docker.com) and share it with others! +> **Note:** +> +> This guide will show the mechanics of building a MongoDB container, but +> you will probably want to use the offical image on [Docker Hub]( https://registry.hub.docker.com/_/mongo/) + Using Docker and containers for deploying [MongoDB](https://www.mongodb.org/) instances will bring several benefits, such as: @@ -59,8 +64,8 @@ a MongoDB repository file for the package manager. # Installation: # Import MongoDB public GPG key AND create a MongoDB list file - RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv 7F0CEB10 - RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list + 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 After this initial preparation we can update our packages and install MongoDB. @@ -70,7 +75,7 @@ After this initial preparation we can update our packages and install MongoDB. > **Tip:** You can install a specific version of MongoDB by using a list > of required packages with versions, e.g.: > -> RUN apt-get update && apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1 +> RUN apt-get update && apt-get install -y mongodb-org=3.0.1 mongodb-org-server=3.0.1 mongodb-org-shell=3.0.1 mongodb-org-mongos=3.0.1 mongodb-org-tools=3.0.1 MongoDB requires a data directory. Let's create it as the final step of our installation instructions. @@ -86,7 +91,7 @@ the `EXPOSE` instruction. EXPOSE 27017 # Set usr/bin/mongod as the dockerized entry-point application - ENTRYPOINT usr/bin/mongod + ENTRYPOINT ["/usr/bin/mongod"] Now save the file and let's build our image. @@ -133,11 +138,11 @@ as daemon process(es). # Basic way # Usage: docker run --name -d / - $ docker run --name mongo_instance_001 -d my/repo + $ docker run -p 27017:27017 --name mongo_instance_001 -d my/repo # Dockerized MongoDB, lean and mean! # Usage: docker run --name -d / --noprealloc --smallfiles - $ docker run --name mongo_instance_001 -d my/repo --noprealloc --smallfiles + $ docker run -p 27017:27017 --name mongo_instance_001 -d my/repo --noprealloc --smallfiles # Checking out the logs of a MongoDB container # Usage: docker logs @@ -145,7 +150,23 @@ as daemon process(es). # Playing with MongoDB # Usage: mongo --port - $ mongo --port 12345 + $ mongo --port 27017 + + # If using boot2docker + # Usage: mongo --port --host + $ mongo --port 27017 --host 192.168.59.103 + +> **Tip:** +If you want to run two containers on the same engine, then you will need to map +the exposed port to two different ports on the host + + # Start two containers and map the ports + $ docker run -p 28001:27017 --name mongo_instance_001 -d my/repo + $ docker run -p 28002:27017 --name mongo_instance_002 -d my/repo + + # Now you can connect to each MongoDB instance on the two ports + $ mongo --port 28001 + $ mongo --port 28002 - [Linking containers](/userguide/dockerlinks) - [Cross-host linking containers](/articles/ambassador_pattern_linking/) diff --git a/docs/sources/examples/mongodb/Dockerfile b/docs/sources/examples/mongodb/Dockerfile index c17a6360e5..3513da4716 100644 --- a/docs/sources/examples/mongodb/Dockerfile +++ b/docs/sources/examples/mongodb/Dockerfile @@ -7,9 +7,8 @@ MAINTAINER Docker # Installation: # Import MongoDB public GPG key AND create a MongoDB list file -RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv 7F0CEB10 -RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list - +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