Pages

Wednesday, January 15, 2014

MongoDB Server on Fedora, Using Docker

In just a few simple steps, you can have an instance of MongoDB up and running in a Docker container. Here's how you run it. This was tested on Docker 0.7.2

Grab the dockerfile from either of these locations:

https://github.com/scollier/Fedora-Dockerfiles

or:

https://git.fedorahosted.org/cgit/dockerfiles.git/

Get the version of Docker

# docker version

To build:



Copy the sources down -

# docker build -rm -t /mongo .

To run:

# docker run -d -p 27017 /mongo

Watch for the database to initialize and start listening (using the container ID from "docker run":

# docker logs 3a2aaa5b803f597732b18

Tue Dec 17 20:34:42.655 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0 reslen:37 360ms
Tue Dec 17 20:34:42.661 [websvr] admin web console waiting for connections on port 28017
Tue Dec 17 20:34:42.725 [initandlisten] waiting for connections on port 27017

Get the port that the container is listening on:

# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8fc42d19fd3 /mongo:latest /usr/bin/mongod 4 minutes ago Up 4 minutes 0.0.0.0:49158->27017/tcp ecstatic_thompson



To test, Find the IP Address of the container.


# docker inspect c8fc42d19fd3 | grep -i ipaddr
"IPAddress": "172.17.0.28",








From the host, run the MongoDB client and connect to the MongoDB server running inside the container.  You can install the mongo-10gen package to get the client tools.

# mongo --host 172.17.0.28 --port 49158

MongoDB shell version: 2.4.6
connecting to: 127.0.0.1:49158/test
>

This is what it looks like.

No comments:

Post a Comment