What is Docker?

The Docker (https://www.docker.com/) project is a container platform, which lets you run your applications in isolated environments. Docker leverages existing Linux technologies like cgroups (https://en.wikipedia.org/wiki/Cgroups) to provide a set of high-level tools to drive a collection of running processes. On Windows and macOS, Docker interacts with a Linux Virtual Machine, since a Linux kernel is required.

As a Docker user, you just need to point which image you want to run, and Docker does all the heavy lifting by interacting with the Linux kernel. An image in that context is the sum of all the instructions required to create a set of running processes on the top of a Linux kernel to run one container. An image includes all the resources necessary to run a Linux distribution. For instance, you can run whatever version of Ubuntu you want in a Docker container even if the host OS is a different distribution.

While it is possible to use Windows, Flask microservices should always be deployed under a Linux or BSD-based system--the rest of this chapter makes the assumption that everything is installed under a Linux distribution such as Debian.

If you have already installed Docker in Chapter 6, Monitoring Your Services, to set up a Graylog instance, you can jump directly to the next section of this chapter, Docker 101.

If not, you can visit the Get Docker section of the page at https://www.docker.com/get-docker to install it. The community edition is good enough for building, running, and installing containers. Installing Docker on Linux is a no-brainer-- you can probably find a package for your Linux distribution.

For macOS, Docker uses a VM to run a Linux Kernel. The latest versions are based on HyperKit (https://github.com/moby/hyperkit), which leverages bhyve, a BSD Hypervisor. Running Docker via a VM adds a bit of overhead, but it is quite lightweight, and works well with modern hardware. Hypervisors are becoming a commodity in all major operating systems.

Under Windows, Docker uses the Windows built-in Hyper-V, which might need to be enabled. The feature can usually be enabled via a command-line shell with a DSIM call, as follows:

$ DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V 

If the installation was successful, you should be able to run the docker command in your shell. Try the version command to verify your installation like this:

$ docker version 
Client:
Version: 17.03.1-ce
API version: 1.27
Go version: go1.7.5
Git commit: c6d412e
Built: Tue Mar 28 00:40:02 2017
OS/Arch: darwin/amd64

Server:
Version: 17.03.1-ce
API version: 1.27 (minimum version 1.12)
Go version: go1.7.5
Git commit: c6d412e
Built: Fri Mar 24 00:00:50 2017
OS/Arch: linux/amd64
Experimental: true

A Docker installation is composed of a Docker server (the engine that's being executed by a daemon) and a Docker client (the shell commands like docker).

The server provides an HTTP API, which can be reached locally through a UNIX socket (usually, ;/var/run/docker.sock) or through the network.

In other words, the Docker client can interact with Docker daemons running on other boxes.

For managing Docker manually, the Docker command line is great. However, in case you need to script some of your Docker manipulation, a Python library like docker-py (https://github.com/docker/docker-py) lets you do everything from Python. It uses requests to perform HTTP calls against the Docker daemon.

Now that Docker is installed on your system, let's discover how it works.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset