Get Started With Docker on Your Non-Linux PC
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
Docker is based on server-client architecture.
Here’s a typical Docker installation on a Linux PC:
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.
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.
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:
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.
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:
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:
You should get a response like this:
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:
You’ll see the message:
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:
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.
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.