Microservices with Docker - part 2

A gentle, pragmatic introduction to Microservice Architecture and Docker.

In the previous part 1 of this post series, we introduced the Microservice Architecture paradigm and given a preliminary introduction to the Docker platform.

In this part 2 we are going to learn how to start using Docker, installing it on OS X embracing a pragmatic approach.

Running Docker, pulling Images and running Containers, etc… requires a Linux machine.
On Mac OS X we need a Virtual Machine.
Starting from version 1.8 Docker deprecated the old Boot2Docker command line tool in favor of the new Docker Machine. Then, they provide an handy Docker Toolbox to install Docker Machine as well as the other Docker tools.

Just follow the documentation to install the Docker Toolbox and to run it (on OS X).

When the Docker Machine (which creates Docker hosts) is running on your Mac, you’re ready to interact with Docker through the Docker Client command line interface (docker).

After installing Docker Toolbox, run Docker Machine from Applications/Docker choosing Docker Quickstart Terminal.app

After some init operations you should see something like this on a Terminal window...

Basically, we’ve just created a Docker Machine and now it is ready to accept commands through our Docker Client.

A Docker Machine lets you create Docker Hosts on your computer (or on cloud). It automatically creates hosts, installs Docker on them, then configures the Docker Client to talk to them. A machine is the combination of a Docker host and a configured Docker Client.

Docker Machine provides several commands for managing them. Using these commands you can:

- start, stop, and restart a host
- upgrade the Docker Client and daemon
- configure a Docker client to talk to your Docker Host
- etc...

Summarizing: our previous step created a new Docker Host on OS X, run a new Docker machine called default and configured a Docker Client. The following picture shows our Docker architecture on OS X.

The configured Docker system on Mac OS X

We're ready to explore some essential Docker commands.

Basic Docker Machine commands

$ docker-machine --help
Prints the command general help.

$ docker-machine ls
Shows all the existing Docker machines.

$ docker-machine start <machine>
$ docker-machine stop <machine>
Start and Stop machines. E.g.,  $ docker-machine start default

$ docker-machine ip <machine>
Get the IP address of a machine.

For a comparison between old (deprecated) Boot2Docker commands and Docker Machine please refer to this documentation.

Now that we have a Docker host running with a default machine we’re ready to know how to use the Docker Client command line interface.

Common Docker Commands

$ docker --help
$ docker <CMD> --help

it prints the help, where CMD is a specific docker command, like run

$ docker pull <IMAGE_NAME>
Downloads an Image from the Docker Hub repository given its name.

$ docker run <IMAGE_NAME>
Downloads locally, if not already done, an Image from repository and runs a Container based on it.


$ docker run -i -t ubuntu

Runs an Ubuntu container:
-i : interactive connection grabbing STDIN
-t: pseudo tty-terminal

$ docker run -i -t -p 8080:3000 node-express
Runs an Image as a Container, mapping internal 3000 port to 8080 as visible by external requests.

$ docker ps -a
Lists all Containers (not only running Containers)

$ docker images
Lists all downloaded Images

$ docker commit -a "Your Name <youremail@email.com>" -m "ubuntu and node" CONTAINER_ID node-ubuntu:0.1
Creates a new image from the container given its CONTAINER_ID, tagging it with a version.

$ docker tag node-ubuntu:0.1 node-ubuntu:latest
Adds the latest tag to the existing image node-ubuntu
When a docker run command is launched on that Image without a version, the latest tagged version is used.

$ docker rm <YOUR_CONTAINER_ID>
Removes a Container

$ docker rmi <YOUR_IMAGE_ID>
Removes an Image

Example n.1: Running the hello-world container

The “hello-world” is a Docker Image, thus published on the Docker Hub, in order to explain how Docker works. Simply, it allows to run a container which prints some useful information.

To download the Image and run a Container based on that, simply run the command:

$ docker run hello-world

Resulting in:

Reading the printed message on the Terminal show you what’s happened.

Now, running the command:

$ docker ps -a
it will show you all the containers, running or not, on your Docker Host and you should be able to find the hello-world Container and its current (exited) status.

Running the command:

$ docker images
it will show you all the locally downloaded Images, including the hello-world one.

A man and his rocks

Solid Landscapes.
Sulcis, Sardinia.

Many thanks to Ivano & Kyre of Pretziada (visit and follow their amazing project!)

Microservices with Docker - part 1

A gentle, pragmatic introduction to Microservice Architecture and Docker.

In this part 1 of a post series, we are going to give a brief introduction to Microservices and to the Docker platform.

Microservice Architecture

Microservice architecture is a way of designing software applications as composed of modules of independently deployable services.
Thus, an application following the Microservices paradigm is built of small services, each running its own process and communicating through some APIs, HTTP, or other.
A Microservice Architecture-based  application is opposite to “old-style” Monolithic applications.

(Picture from M. Fowler, Microservices)

As intuitable, the basic components in a Microservice Architecture are represented by services, which are independently deployable software components. A service is somewhat different from a library. Examples of services in a Microservice Architecture application can be: an authentication deployed module, an API part dedicated to handle payments, a user database service, ...

For example, as stated in M. Fowler, Microservices, if you have a classic application depending on several libraries:

“a change to any single component results in having to redeploy the entire application. But if that application is decomposed into multiple services, you can expect many single service changes to only require that service to be redeployed.”

Microservices aren’t a relative new concept, but they’re quickly becoming popular, facing common architectural issues about development, deployment and scaling of (simple to) complex modern web applications. Microservice Architecture paradigm is platform and programming languages agnostic. For example, Docker could be a suitable platform to design, develop, deploy and run Microservices on a controlled, comfortable environment. But, also you can build your Microservices implementation using other tools or platforms or by building your infrastructure as well.

What is Docker?

As described on the Docker website, Docker is:

“a platform for developers and sysadmins to develop, ship, and run applications. Docker lets you quickly assemble applications from components and eliminates the friction that can come when shipping code. Docker lets you get your code tested and deployed into production as fast as possible.”

Screen Shot 2015-04-13 at 11.09.22.png

Classic Virtual Machines vs. Docker (Picture from Docker docs)

Thus, why Docker?

  • - to build and scale Microservice Architecture-based applications
  • - to isolate and independently develop Microservices
  • - to simplify a development configuration/environment
  • - to share applications and their environment with other developers (in the same team or not)
  • ...
Basically, Docker technology consists of:

The Docker Engine

A lightweight and powerful container virtualization technology combined with a work flow for building and containerizing applications. The Docker Engine daemon is the Docker component which builds, runs and distributes the Docker Containers.

The Docker Hub

A service for sharing and managing application images. It is a repository which holds usable Docker Images. You can use the Docker registry for free or under a fee and have open-source public  images and private Images.

The Docker Client

The Docker client connects to the Docker Engine Daemon (local or remotely) and accepts all the Docker commands, like docker pull or docker run. 


Images are templates for Docker applications. An Image it’s like a composable component to use to create application stacks. For example, can be an Ubuntu image or a Redis image based on Ubuntu, etc…


A Container is created from a Docker Image. Think about it as an instantiation (a Container, a running instance) from a class (an image) in the OOP paradigm. Containers can be started, stopped, etc…

The Docker Architecture overview (from Docker website)

On a Linux-based host, a Docker environment can be summarized by the following picture. We run a Docker Engine to build and run our Containers - created from Docker Images - and managing the Docker environment through the Docker client command.

A Docker environment in case of a Linux host

So, for example, with Docker we can quickly build and deploy a microservices-based application which uses NGINX and node.js Images, pulling them from the Docker Hub and instantiating and running them as Containers. We can run our code on the second, node.js Container and link the NGINX container to serve as reverse proxy for the entire Web app. All of them as Microservices running on separate modules.
In the (coming soon) part 2 of this article series we will describe how to pragmatically use Docker and its commands to pull Images, to run Containers and to manage them. Where, on a future post in this series we will learn how configure and run a dockerized node.js/express application.

Stay tuned!

The Thin Ice

The Path to Roots

Toward Barrancu Mannu, Santadi, Sulcis, Sardinia.
Bronze Age, ca. 1300 BC

All photos: iPhone 6 + VSCO Cam

Lisboa vs. Vienna in two weeks

Lisboa, Lisbon, Lisbona.
Rainha do Mar.

...and then, Vienna: majestic.