Sunday February 8, 2015 - tags:    docker, microservice

A dockerised micro-service node.js architecture

![](/content/images/2015/05/docker.png) ![](/content/images/2015/05/nodejs.png)


This is the first in a series of posts where I explore how to setup a dockerised micro-service architecture with node.js.

The source code for these posts can be found here: dockerised-micro-service-node-js-architecture

I will start this off with a few posts on Docker an open source project that automates the deployment of applications inside a lightweight container. In this post we will install and setup docker.

In this post

Install docker

There is no native docker support on Mac OS X; so you will need to install VirtualBox and boot2docker.

Install VirtualBox

You can find VirtualBox binaries here:

Install boot2docker

You can find boot2docker binaries here:

There is a video here on how to setup boot2docker:

Basically you need to install the Boot2Docker-*.pkg file and then run the application which configures boot2docker.

Running this application will initialise, setup ssh keys and environment variables and start boot2docker.

Check if boot2docker is running

At this point boot2docker should be running, you can check this using:

$ boot2docker status

Which should return


Restart boot2docker

Lets go through the process of restarting boot2docker, as when boot2docker stops there are a couple of important steps you will need to take.

First lets stop and start boot2docker.

Stop boot2docker
$ boot2docker stop
Start boot2docker
$ boot2docker up

You should get the following response:

Writing /Users/USERNAME/.boot2docker/certs/boot2docker-vm/ca.pem
Writing /Users/USERNAME/.boot2docker/certs/boot2docker-vm/cert.pem
Writing /Users/USERNAME/.boot2docker/certs/boot2docker-vm/key.pem

To connect the Docker client to the Docker daemon, please set:
    export DOCKER_CERT_PATH=/Users/USERNAME/.boot2docker/certs/boot2docker-vm
    export DOCKER_TLS_VERIFY=1
    export DOCKER_HOST=tcp://

Running boot2docker up creates certificates and keys, it also requires you to run the three export commands to connect the client to the docker daemon.

Set the DOCKER_HOST environment variable

$ export DOCKER_HOST=tcp://
$ export DOCKER_CERT_PATH=/Users/USERNAME/.boot2docker/certs/boot2docker-vm

Run these two commands and check $DOCKER_HOST and the ip address has been set correctly.

Check the docker host
Get your boot2docker vm ip address
$ boot2docker ip  

Check docker installation

You can check to see if you have docker installed correctly and get information on you docker instance by running:

Docker version
$ docker version
Information on docker
$ docker info

Upgrade the boot2Docker VM Image

If you wish to take an upgrade run the following:

$ boot2docker stop
$ boot2docker download
$ boot2docker up

Uninstall boot2Docker

If you would like to uninstall boot2Docker use this script.


if [ "$(which boot2docker)" == "" ]; then
	echo "boot2docker does not exist on your machine!"
	exit 1

if [ "${USER}" != "root" ]; then
	echo "$0 must be run as root!"
	exit 2

echo "Stopping boot2docker processes..."
boot2docker stop && boot2docker delete

echo "Removing boot2docker executable..."
rm -f /usr/local/bin/boot2docker

echo "Removing boot2docker ISO and socket files..."
rm -rf ~/.boot2docker
rm -rf /usr/local/share/boot2docker

echo "Removing boot2docker SSH keys..."
rm -f ~/.ssh/id_boot2docker*

echo "Removing boot2docker OSX files..."
rm -f /private/var/db/receipts/io.boot2docker.*
rm -f /private/var/db/receipts/io.boot2dockeriso.*

echo "Removing Docker executable..."
rm -f /usr/local/bin/docker

echo "Docker removed!"

Working with virtual box

If you get into trouble with virtual box here are a couple of commands to assist.

View virtual machines running on virutal box
VBoxManage list runningvms

Will return:

"boot2docker-vm" {guid}
Poweroff the boot2docker virtual machine
VBoxManage controlvm boot2docker-vm poweroff