What is Docker and how to use it
Maybe you’re just considering a career in DevOps, or maybe you’re already working in the field. Either way, if Docker isn’t on your resume, it’s time to learn it. It’s one of the most in-demand skills for any DevOps professional.
What is Docker?
In simple terms, Docker is a platform that makes it easy to build, run, manage, and distribute applications. It does all this by virtualizing the operating system of the computer on which it is installed and running.
Docker is open source software, and the easiest way to compare it to how it works is to use shipping containers. Just think about it, shipping companies once faced similar problems:
- How to transport different (incompatible) types of goods together (e.g. food with chemicals or glass with bricks)?
- How to handle packages of different sizes in the same vehicle?
With the introduction of containers, it became possible to transport bricks and glass, chemicals and food, and much more together. Cargo of different sizes can be distributed across standardized containers that are loaded/unloaded by the same vehicle.
But back to containers. When you develop an application, you need to provide the code along with all its components, such as libraries, server, databases, etc. You may find yourself in a situation where the application works on your computer, but refuses to run on another user's device. Each of these applications may use its own separate, specific set of libraries and dependencies. This problem is solved by creating software independence from the system.
How is it different from virtualization?
Virtualization was originally intended to eliminate such problems, but it has significant drawbacks:
- slow loading;
- possible payment for providing additional space;
- not all virtual machines (VM) support compatible use;
- VMs that do often require complex configuration;
- the image can be too large, since the "additional OS" adds a gigabyte of space to the project on top of the operating system, and in most cases several VMs are installed on the server, which take up even more space.
Docker simply divides the OS kernel into all containers (Docker container), which operate as separate processes. This is not the only such platform, but, undoubtedly, one of the most popular and in-demand.
How Docker Works
The machine on which Docker is installed and running is commonly referred to as the Docker Host or simply the "host".
To deploy an application to a host, a logical entity is first created on it to host this application. In Docker terminology, this logical entity is called a Container or, more precisely, a Docker Container.
A Docker container does not have any operating system installed and running. But it will have a virtual copy of the process table, network interfaces, and file system mount points. All of this will be inherited from the operating system of the host on which the container is hosted and running.
Thus, the kernel of the host operating system is shared between all containers running on it.
This allows each container to be isolated from others hosted on the same host. That is, containers with different application requirements and dependencies can run on the same host, as long as they have the same operating system requirements.
In short, instead of virtualizing the hardware components, Docker virtualizes the operating system of the host on which it is installed and running.
Key Benefits of Using Docker
- Multiple applications with different requirements and dependencies can reside together on a single host as long as they have the same operating system requirements.
- Optimized storage: A single host can host a large number of applications, as containers typically take up only a few megabytes and consume very little disk space.
- Reliability: The container does not have a separate operating system. Therefore, it consumes very little memory compared to a virtual machine where the OS is installed and launched. Thanks to this, the boot time is also reduced to a few seconds, while a virtual machine needs a couple of minutes to boot.
- Reduced Costs: Docker is less demanding regarding the hardware it runs on.
Disadvantages of Using Docker
- Applications with different operating system requirements cannot be hosted on the same Docker host. Let's say we have four different applications, three of which run on Linux and one on Windows. In this scenario, the first three can be hosted on the same Docker host, while the one that requires Windows will require a different host.
Supported platforms
Docker not only runs on its native OS, Linux, but is also supported by Windows and macOS. The only difference from interacting with Linux is that on macOS and Windows, the platform is encapsulated in a tiny virtual machine. At this point, Docker for macOS and Windows has reached a significant level of usability.
Additionally, there are many additional applications, such as Kitematic or DockerMachine, that help install and use Docker on platforms other than Linux.
Terminology
- A container is an executable instance that encapsulates the required software. It is made up of images. It can be easily deleted and recreated in a short period of time.
- An image is the basic unit of every container. Depending on the image, it may take some time to create.
- A port is a TCP/UDP port in its original meaning. To keep things simple, we assume that ports can be exposed to the outside world or attached to containers (accessible only from these containersand invisible to the outside world).
- A volume is described as a shared folder. Volumes are initialized when a container is created and are used to persist data regardless of the container's lifecycle.
- A registry is a server that stores images. Compare it to GitHub: you can pull an image from the registry to deploy it locally, and you can also push images to the registry locally.
- Docker Hub is a public repository with an interface provided by Docker Inc. It stores a lot of images. The resource is a source of "official" images made by the Docker team or created in collaboration with the software developer. For official images, their potential vulnerabilities are listed. This information is open to any registered user. Both free and paid accounts are available.
Docker Editions
Docker is available in two editions:
- Community Edition, CE (community edition)
- Enterprise Edition, EE (enterprise edition)
Community Edition is suitable for individual developers and small teams. This edition provides limited functionality compared to Enterprise Edition.
Enterprise Edition, in turn, is suitable for large teams and for using Docker in a production environment.
Enterprise Edition is divided into three different editions:
- Basic Edition
- Standard Edition
- Advanced Edition
How to Install Docker
Here are links to the official Docker Community Edition installation guides. They are pretty straightforward, so you can use them to install Docker on your machine.
CentOS Linux
Debian Linux
Fedora Linux
Ubuntu Linux
Microsoft Windows
MacOS