Using a containerized MongoDB

Don't have backups already? This might be interesting for you: Automated Backup of MongoDB Containers

Official MongoDB images are available from Docker Hub.

In our case we grab the latest release from the 2.4 stream (2.4.14 at the time of writing).

$ docker pull mongo:2.4.14

Let's give the container the name planets-mongodb and store the actual data outside of the container on the host system:

$ docker run --name planets-mongodb --detach --volume=/home/planets/data:/data/db mongo:2.4.14

Now we can connect directly to the running instance via mongo shell running inside a container as well:

$ docker run --link planets-mongodb:mongo -it --rm mongo sh -c 'exec mongo "$MONGO_PORT_27017_TCP_ADDR:$MONGO_PORT_27017_TCP_PORT/planets"'
MongoDB shell version: 2.4.14
connecting to: 172.17.0.18:27017/planets
Welcome to the MongoDB shell.
...
> db
planets

Or with our application planets-server (the Planets backend):

$ docker run --link planets-mongodb:planets-server --name planets-server -d planets-server
Show Comments