On anything that got to do with software development

Month: March 2018

My experience with Docker – Part 2


In this article, My experience with Docker, I touched on what Docker is and how it works. I didn’t get to actually building a Docker container. In this article, I am going to look at how one can get started in using Docker based on the research I did and also on my personal experience.


First thing first, you need to install the Docker engine. In order to install Docker CE, you need the 64-bit version of either Ubuntu Artful 17.10 (Docker CE 17.11 Edger and higher only) or Xenial 16.04 (LTS) or Trusty 14.04 (LTS). Here is how you install Docker CE:

  • sudo apt-get update :> updates the apt package index
  • sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y :> install packages to allow apt to use a repository over HTTPS
  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add – :> add Docker’s official GPG key
  • sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable” :> this sets up a stable repository.
  • sudo apt-get update :> updates the apt package index
  • NOTE: in order to install a specific version of Docker, run the following command:
    • apt-cache madison docker-ce
  • sudo apt-get install docker-ce=17.12.1~ce-0~ubuntu -y :> install Docker version 17.2.1. NOTE: this will vary depending on the version you would have selected from the above command.
  • sudo docker run hello-world :> confirm that Docker installation was successful.

Docker concepts

There following are concepts one needs to know first before getting hands dirty with Docker:
Note: for more detailed explanation click here.

Docker Engine  is a client-server application with the following major components:

  • A server which is a type of long-running program called a daemon process.
  • A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.
  • A command line interface (CLI) client -> the docker command.

Docker Daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks and volumes. It can also communicate with other daemons to manage Docker services.

Docker client (docker) is the means by which many Docker users interacts with Docker. Commands such as docker run, when executed, they are sent to dockerd by the client so that the daemon can carry out the commands.

Docker image is a read-only template with instructions for creating a Docker container.

Docker container is a runnable instance of an image.

Docker registry stores Docker images.

Getting started

Now that Docker is installed and have verified that all is good with the installation, to get started with creating a container, first thing one needs to do is to create a file called Dockerfile. This file is used to create the container and it is in this file where instructions on what is needed for the container to be operational are set. For instance, here is how a simple file would look like:

# Use an official Ubuntu 14.04 runtime as a parent image
FROM ubuntu:14.04

# Run echo when the container starts
CMD echo “Hi there, just started my first container!!!”

The instructions here are simple, use Ubuntu 14.04 as a parent image and then output “Hi there, just started my first container!!!” when the container launches. Once the file has been created, the next step is to build an image by running the command below:

docker build -t my-first-image .

The command will build the image with a tag my-first-image which gives the image a friendlier name. Once the build is done, run any one of the following commands and they will list the images you have locally:

  • docker images
  • docker image ls

From the above, we can see that the image has been created. The next step is to run the image and create a container as follows:

docker run –name my-first-container my-first-image and it will output Hi there, just started my first container!!!

By just running the command above, a container has been created and to see the container, run the following command:

docker ps -a

By just running the command above, it will list containers and will provide details such as container id (auto generated by Docker client), image (the image used by the container), created (time the container was created), status (provides the status if the container is running or not), ports (provides ports that are exposed for the container) and name (container name).

So far we created a Dockerfile, the file that has  instructions on what is needed to get the container operational, ran the build command to create Docker image and finally ran the command to build Docker container.

The commands we ran so far are as a follows:

  • docker images or docker image ls :> lists docker images
  • docker build [options] :> builds the image from the Dockerfile
  • docker ps -a :> lists the containers

These are just a few commands, there are more just run docker and it will give the list commands you can run and more information on what you can do with the Docker client.


From this article we saw how one can install Docker, create a Docker image and a Docker container. Next article will look on how Docker can be part of continuous integration.

Docker overview


My experience with Docker


This is a basic introduction to what Docker is based on personal experience and what I understood from online research.

What is Docker?

One needs to understand what containerization is in order to understand what Docker is. I am going to use an example here to explain some concepts first. Lets say you are relocating to a new place. You start to pack your stuff in different boxes or containers. One container will have plates, the other coffee mugs and another electric appliances and so forth. Once all the packing is done, you are going to put these containers in a vehicle and transport your stuff to the new place.

The act of putting stuff in containers and transporting them is known as containerization.  You cannot mix your plates with electric appliances, but you can put them in different containers and transport them all at once using one vehicle.

The same applies with operating software, they cannot mix or in other words they cannot both boot simultaneously when a computer is powered on. But due to virtualization, you can have your base operating software as Windows and have Linux running on a virtual machine. One a single laptop or computer you have two operating software running. Back to our moving example, lets say one of the container is a cooling container for keeping meat fresh. But for this container to work, it must also get some of the fuel from the vehicle that is transporting these containers. The cooling container is sharing resources with the vehicle. This is not efficient which is the same with virtual machines (VMs). VMs share resources such as CPU, hard drive space and RAM and this is not efficient especially if the VM needs to operate heavy processes.

Now imagine if the cooling container has its own source of fuel and all it needs is to be placed on the transporting vehicle. At the end you have plates container, electric container and cooling container all being transported with one vehicle.

From the above example we can establish that a container is used to enclose and hold something either for storage, packaging or for transportation. Then containerization is a system of transporting containers. With that in mind, think of application containerization as enclosing or packaging files or libraries needed to run a desired software. This then brings us to Docker. In a nut shell, Docker is a software used to containerize other software or applications. It is developed by Docker Inc and it is open source.

How Docker works

Using our delivery truck example, the image below will show how docker works in a nut shell:

The image below is going to be more technical on how Docker works on a real machine:

As shown from the diagram above, Docker is sharing the Linux’s kernel which in turn will enable the containers to run on the same kernel. Using our delivery analogy, think of the Docker container for HDP Sandbox as the cooling container that requires its own fuel to cool the meat. The Docker container for HDP Sandbox runs on CentOS, has Java and openjdk and other applications include Hive, Ambari, Spark, Yarn just to mention a few. Its own operating software is CentOS yet the base operating software is Ubuntu 16.04.4 LTS. The cooling container requires petrol to operate its cooling engine, a hypothetical example, whereas the delivery truck is running on diesel. In addition, this is different from Docker container for ElasticSearch and Spark. They have their own needs that are separate and independent to those of the HDP Sandbox.

So Docker has containerized these application down to the basics, that is, share the kernel and run your own operating software. The requirements for this to run are not that much, hence, more containers can be added. In addition, due to the fact that the Docker engine allows applications to run on the same kernel with the base operating software, the applications can be started faster. Lastly, by virtue of these applications having their own operating software, the applications can run anywhere as long as Docker is installed on the host / base operating software. Again, using the delivery analogy, if the new place you are moving to is say abroad, the delivery truck will deliver the containers to an airport. Once at the airport, the containers will be transported using an airplane.

If you put the Docker containers for Spark, HDP Sandbox and ElasticSearch on a machine with Mac or Windows, they will run the same way they would on a machine with Linux.


In conclusion, Docker is a software that is used for application containerization. It is not the only containerization software, CoreOS released Rocket. Microsoft is working on its own software for containerization called Drawbridge.

You might be then wondering how these containers are build and once they are built how are they managed. In future articles I will look at how I use Docker and what I use to manage the containers. Back to our moving analogy, at the airport, planes are managed so that they land on the right runway, avoid air collisions and also takeoff at the right time. This again is similar with Docker containers, they need to be managed so that those that need to communicate with each other they can do so. Therefore in future articles I will also look at Kubernetes, an application that I use to manage Docker containers.

Containerization 1
Containerization 2

© 2020 Tendai

Theme by Tendai BepeteUp ↑