/ Tutorial , Technology , Docker .

An Introduction to Docker

What is Docker?

Docker is a tool that simplifies building, shipping and running applications. Docker containerises your code, making it easier to transport and more reliable to use.

Docker relies on images and containers, they are your fundamental building blocks in Docker. What are they?

Images

An image is the blueprint to running your application. It contains instructions on how to run your application, including all the dependencies and set-up work. It is a read-only template, comprised of layered filesystems that allow sharing of common files. Images are used to build Docker containers.

Containers

A container is an isolated and secure container created from an image that can be run. started, stopped, moved and deleted. The container contains the actual application as opposed to an image, which is the instructions on how to run the application.

What's the difference between containers and Virtual Machines?

The major difference between Virtual Machines (VMs) and containers is that VMs are bigger, because they package the OS with each VM and each VM sits on top of a hypervisor (cite). With containers, all running containers share a common kernal all sitting on top of the Docker Engine.

Figure 1. Containers vs Virtual Machines

Figure 1. Containers vs Virtual Machines, courtesy of Docker Inc. and RightScale Inc.

It's kind of like the difference between starting an application vs starting your computer and then the application. It's a lot faster to skip the whole turning on the pc!

The benefits of Docker

There are a variety of benefits, some of which are:

  • Accelerate developer onboarding
  • Eliminate app conflict
  • Envorinment consistency
  • Ship software faster and more reliably

Accelerate developer onboarding

Getting new developers on projects is usually a long and arduous process and this is because of the time it takes to set-up the development environment on their machine, getting all of the frameworks, source files etc that is required for an application and then sorting out permissions and installation issues. Docker can eliminate a lot of this pain, because all you do is install docker and run the container! You could literally just follow a step-by-step guide to get the app running on a new machine in minutes.

Eliminate app conflicts

Many developers have had an experience of wanting to upgrade to the latest version of a language or framework but have been told to wait a while, because of the impact it could have on other running applications. With Docker this isn't a problem because all containers are isolated from one another and therefore won't impact each other. This means that you could have two apps both running Node.js, one of them is ready to update to the latest version but the other will break if you update Node. With Docker you can only upgrade the applications that are ready.

Environment consistency

Another issue many of us have faced in the working world is thinking we've got parallel tracks for the development/staging/production environments and then being surprised by the fact that they were not!

Docker can alleviate this issue because it packages environmental dependencies within the container, meaning you can start on the same base OS and then just swap out the container you're using in all environments.

Shipping software

All of the above contribute to making it easier and faster to ship code, using containers increases the reliability of your application.

The Docker Toolbox

Docker Toolbox provides image and container tools which allow you to write images and build containers. The toolbox includes: Docker Client, Docker Machine, Docker Compose and Docker Kitematic. It also includes VirtualBox under the hood for Windows and Mac installations, Docker only runs natively on Linux and Windows Server.

Docker Client

Docker Client is how we interact with and view our images & containers. It allows you to start, stop, restart and inspect containers.

Docker Machine

Docker Machine is a tool that lets you install Docker Engine on virtual hosts and manage these hosts with Docker Machine commands. Using these commands you can start, stop, restart and manage your environment in general.

Docker Compose

Docker Compose allows us to run multiple containers in unison. Take a typical web application for example, we can use Docker Compose to run containers for our web server, database and cache server all while allowing them to communicate with each other.

Docker Kitematic

Docker Kitematic is a relatively new addition to the Docker Toolbox, it provides a GUI for docker images. Kitematic allows you to browse the Docker Hub and Store, download images, build containers and interact with the containers you've built.

Docker in action

This is the tutorial part of this post! We're going to set-up a basic "Hello World!" nginx server, using Docker Kitematic. We'll go through installing Docker all the way to running the container. Let's go!


Installing Docker

Firstly we install Docker Toolbox. Go to the Docker Toolbox download page and download the toolbox for your platform.

Note: For Windows users, you must ensure that you have virtualisation enabled. To check this, open task manager (ctrl + alt + del) and open the performance tab. If this is not enabled then you will need to enable this, use Google to find out how!

Task Manager screenshot, showing virtualisation status

Now you have two Docker programs installed, the Quickstart Terminal and Docker Kitematic. Open up the Docker Kitematic and we can begin.

Getting started with Docker Kitematic

Before we start using Docker, you need to make an account here.

Screenshot of Kitematic

Kitematic will link back to the webpage for available images, letting you read about image and see the comments people have left.

If you open the Recommended tab (upper-right corner) and the first image available should be "hello-world-nginx". Click create!

hello-world-nginx image screenshot

If you search Kitematic for "Hello World" and then click "Create" for the first option, it will build a container from the image and add it to your "Containers" sidebar.

You should now see something like this:

Screenshot of running the container in Kitematic

Well done, you've successfully installed Docker and built and run your own container.

Docker Kitematic is a great visual tool for learning Docker and getting used to the idea of images and containers.


Next time

Next post in this series will be about using Docker Machine and Docker Client as well as utilising various Docker commands.

Leave a comment if you have any ideas on how to use Docker, or any issues you've ran into while following this post!

Leon Hassan

Leon Hassan

SAP Applications consultant, specialising in UI5. Avid fan of Fantasy books and dedicated comic collector. All views are my own.

Read More