1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/docs/sources/examples/mongodb.md
O.S.Tezer f87a97f7df Improve code/comment/output markings & display consistency
This PR aims to increase the consistency across the docs for
code blocks and code/comment/output markings.

Rule followed here is "what's visible on the screen should be reflected"

Issue:

 - Docs had various code blocks showing: comments, commands & outputs.
 - All three of these items were inconsistently marked.

Some examples as to how this PR aims to introduce improvements:

1. Removed `> ` from in front of the "outputs". Eg,
`    > REPOSITORY                 TAG       ID              CREATED` replaced with:
`    REPOSITORY                 TAG       ID              CREATED`.

2. Introduced `$` for commands. Eg,
`    sudo chkconfig docker on` replaced with:
`    $ sudo chkconfig docker on`

3. Comments:
`    > # ` replaced with:
`    # `.

> Please note:
> Due to a vast amount of items reviewed and changed for this PR, there
> might be some individually incorrect replacements OR patterns of incorrect
> replacements. This PR needs to be reviewed and if there is anything missing,
> it should be improved or amended.

Closes:
https://github.com/dotcloud/docker/issues/5286

Docker-DCO-1.1-Signed-off-by: O.S. Tezer <ostezer@gmail.com> (github: ostezer)
2014-05-01 17:52:01 +03:00

89 lines
2.9 KiB
Markdown

page_title: Building a Docker Image with MongoDB
page_description: How to build a Docker image with MongoDB pre-installed
page_keywords: docker, example, package installation, networking, mongodb
# Building an Image with MongoDB
> **Note**:
>
> - This example assumes you have Docker running in daemon mode. For
> more information please see [*Check your Docker
> install*](../hello_world/#running-examples).
> - **If you don't like sudo** then see [*Giving non-root
> access*](/installation/binaries/#dockergroup)
The goal of this example is to show how you can build your own Docker
images with MongoDB pre-installed. We will do that by constructing a
Dockerfile that downloads a base image, adds an
apt source and installs the database software on Ubuntu.
## Creating a Dockerfile
Create an empty file called Dockerfile:
$ touch Dockerfile
Next, define the parent image you want to use to build your own image on
top of. Here, we'll use [Ubuntu](https://index.docker.io/_/ubuntu/)
(tag: `latest`) available on the [docker
index](http://index.docker.io):
FROM ubuntu:latest
Since we want to be running the latest version of MongoDB we'll need to
add the 10gen repo to our apt sources list.
# Add 10gen official apt source to the sources list
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/10gen.list
Then, we don't want Ubuntu to complain about init not being available so
we'll divert `/sbin/initctl` to
`/bin/true` so it thinks everything is working.
# Hack for initctl not being available in Ubuntu
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -s /bin/true /sbin/initctl
Afterwards we'll be able to update our apt repositories and install
MongoDB
# Install MongoDB
RUN apt-get update
RUN apt-get install mongodb-10gen
To run MongoDB we'll have to create the default data directory (because
we want it to run without needing to provide a special configuration
file)
# Create the MongoDB data directory
RUN mkdir -p /data/db
Finally, we'll expose the standard port that MongoDB runs on, 27107, as
well as define an `ENTRYPOINT` instruction for the
container.
EXPOSE 27017
ENTRYPOINT ["usr/bin/mongod"]
Now, lets build the image which will go through the
Dockerfile we made and run all of the commands.
$ sudo docker build -t <yourname>/mongodb .
Now you should be able to run `mongod` as a daemon
and be able to connect on the local port!
# Regular style
$ MONGO_ID=$(sudo docker run -d <yourname>/mongodb)
# Lean and mean
$ MONGO_ID=$(sudo docker run -d <yourname>/mongodb --noprealloc --smallfiles)
# Check the logs out
$ sudo docker logs $MONGO_ID
# Connect and play around
$ mongo --port <port you get from `docker ps`>
Sweet!