Get Started With Docker on Your Non-Linux PC

2 Sep 2015

Though having been around for quite some time now, containers have recently become one of the most sought after technologies. Docker made containerization cool. Seemingly everyone is running—or wants to run—their software in a Docker container. And rightly so. After all, containers are lightweight, easy to deploy, and scalable.

But what if you’re late to the party? If you’re just getting started with Docker, you probably have a thousand questions to ask. Perhaps one of them is: "do I need a Linux box to run Docker? If not, how will that work?"

In this post we'll take a look at that question and get you started on the basics. We’ll learn how to install Docker, create containers from images, and run containers on a non-Linux PC.

Architecture and Terminology

Architecture

Docker is based on server-client architecture.

Here’s a typical Docker installation on a Linux PC:

System Diagram

The client is (predictably) called the Docker client. It serves as the interface to the Docker daemon, i.e. server. The daemon does the heavy-duty tasks of building, running, and distributing the Docker images. Docker components (i.e. the client and daemon) can be placed on the same system, or different systems, based on your requirements.

A top level view of how this works: you issue commands to the client, the client sends them to the daemon, and the server executes them.

Components

Docker has three important components: images, containers and registries.

A Docker image is the software bundle supposed to run on Docker (the Docker container, more specifically). It contains all the files and supporting libraries required to run the software. Anyone can create their own Docker image using the Docker client CLI.

A Docker container can be thought of as a running instance of Docker image. The most important aspect of Docker containers is they run completely isolated from the host system and are independent in terms of software resources.

The Docker registry is a SaaS platform by Docker (the company) that hosts images created by Docker users. Anyone can push or download Docker images from Docker registry. Because the registry software is available to download, you can create a private Docker registry for your organisation, if you want to.

Installation

The Docker daemon uses the Linux kernel, so it isn’t possible to run Docker natively on a non-Linux PC. To get around this, the Docker team created a helper tool called Boot2Docker.

The Boot2Docker installation package contains a VirtualBox virtual machine, the Boot2Docker tool, and Docker itself. The virtual machine included in the package is a lightweight Linux VirtualBox image that provides all the Linux kernel related features required by the Docker daemon.

In effect, what happens is: the Linux VM runs on top of your native OS and the Docker daemon uses the Linux VM for all its Linux kernel dependencies.

Here’s what that looks like:

System Diagram

This may seem convoluted at first. i.e. Why not run your app in a VM directly on your host OS? Why involve Docker as an additional layer? But actually, this setup is kind of neat.

The VM included in Boot2Docker package is not your typical Linux distro with all the bells and whistles. Rather, it’s a small 24 MB download, boots in ~5 seconds, and is stripped down completely to just support the Docker daemon. And once you have Boot2Docker and the VM installed, you have one stripped-down VM, and as many light-weight Docker containers as you want.

Installing Boot2Docker

Download the Boot2Docker installer matching your OS. Install it and follow the instructions. The rest of the process is much the same for Windows and OS X. I’m using OS X, so the rest of the instructions are for OS X. If you are on a Windows system, please refer the Docker documentation page in case the commands don’t work for you.

Once the installation is done, open the Boot2Docker application from the Applications folder. A new terminal window will open up, and several commands will be run in it automatically for you. Those commands start with:

Waiting for VM and Docker daemon to start

Lets see what’s happening.

First of all, it creates a new directory called .boot2docker inside your home directory and places the ISO image file and certificates inside the folder. Finally the boot2docker-vm is executed* *and the Docker daemon is started.

Check this has all worked by running:

$ docker version

You should get a response like this:

Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): darwin/amd64
Server version: 1.7.0
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 0baf609
OS/Arch (server): linux/amd64

Hello World

Finally, lets try the customary Hello World app using Docker. This will give you an idea of how the Docker client can request the Docker daemon to run a Docker image. The Docker daemon checks for the requested Docker image locally and if not found locally, downloads it from the Docker registry (also known as the hub).

To start, run:

$ docker run hello-world

You’ll see the message:

Unable to find image 'hello-world:latest' locally

This means the daemon will now contact the Docker hub to download and run the hello-world Docker image. Once the image is pulled from the Docker hub, the daemon creates a new container from the image. This container is then executed and displays the message "Hello from Docker".

Here’s what that looks like:

latest: Pulling from hello-world
a8219747be10: Pull complete 
91c95931e552: Already exists 
hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd18681cf5daeb82aab55838d
Status: Downloaded newer image for hello-world:latest
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/

Bonus: Kitematic

If you are more of a GUI person and find the command prompt difficult to handle, there’s a new tool called Kitematic just for you. If you’ve not heard about it yet, Docker recently acquired Kitematic. You can download and install Kitematic from the Docker website and quickly create a container from the Docker hub, all via the GUI.

Conclusion

Containers are great for development and running apps isolated from outside world. Docker made it even simpler. With support for non-Linux platforms and simple CLI, it’s easier than ever to have your own container up and running in a matter of minutes.

In this post, we learnt about Docker architecture and its major components. We also saw the installation process and ran our own hello-world container. I hope this gave you a clear idea of how Docker works.

Posted in Docker, Containers

triangle square circle

Did you enjoy this post?