Docker is a set of products and tools of the type platform-as-a-service (PaaS), that uses virtualisation on the level of the operating system to deliver software in packages called containers.
It is a software with open source code. Some of the parts are offered as a commercial service. One of the main advantages is the independency on the operating system and developer tools for your application. Docker secures with the help of isolated containers a unified development environment for Windows, MacOS, and Linux.
Example: We develop the application in PHP for operating system Ubuntu 20.04. However one of the developers uses Windows operating system, another uses MacOS. They don’t need to install or virtualize a complete operating system Ubuntu 20.04 and set LEMP, because Docker has a prepared image for the needs of the application.
Docker greatly facilitates and automates the software development, its distribution and operation.
Behind the main development stands the Docker Inc. founded by Solomon Hykes and Sebastien Pahl, at the Y Combinator Summer 2010, which is a startup incubator, started at the year 2011. Hykes started the Docker project in France as an internal project for dotCloud, which was a platform-as-a-service company.
Docker was revealed to the public in Santa Clara at the conference PyCon in 2013. As an open-source it was released in March 2013. At that time it was using LXC, but soon transferred in version 0.9 to its own environment written in a language Go (Golang). In 2017 Docker created a project Moby, that served for research and testing of the new functions, but is also an upstream for Docker.
Basic dictionary
Concept of project Docker is based on several pillars, that we will introduce shortly and thoroughly explore in other parts of this series.
Image
It is a template, that is focused on the reading and is stored in the registry like hub.docker.com. Acording to this template, Docker creates the container or multiple containers. More specifics by which the docker creates the container, are written in the test file called Dockerfile.
Dockerfile
It is a text file called Dockerfile, to which we write the guide and commands to create a container. Here we can, for example, create a container, that will from the registry hub.docker.com download and run the operating system Ubuntu in the newest version (first line) and then update all software in in and install all hat is necessary for compilation of other tools (second line).
FROM ubuntu:latest
RUN apt-get -y update && apt-get -y upgrade && apt-get install -y build-essential
In the directory, where the file Dockerfile is located, we can now run via terminal the container from the image ubuntu.latest:
docker run -i -t ubuntu /bin/bash
This container called ubuntu will display bash in the terminal and we can start to write commands to the loaded operating system Ubuntu.
Container
It is a running image – for example the one we started via command docker run -i -t ubuntu /bin/bash. Containers are fully or partially isolated from the hosting operating system and we can create, start, stop, move or delete them.
Volume
Containers are by their concept without state and inconsistent. That means that the data are lost upon closing. In reality we often need to work with the data on the level of directories and files. Volume allows to connect the data from the hosting system to the container. It is a principle similar to mount in inux systems.
Network
Network in docker containers serves to connect with the hosting system. For example we may need to open the communication for the web server Nginx on the port 80 in the container and connect it to the por 8080 on the hosting computer.
Docker allows to create the network between specific containers, which is advantageous in more complex systems.
Docker Compose
It is a tool thanks to which we may simplify the creation and setting of the complex environment from multiple containers, network data. Settings for tool Compose is saved in the text file called docker-compose.yml.
Docker Swarm
A tool, thanks to which we can manage multiple installations of project Docker (nodes). It secures the orchestration of this environment.
When and why to use Docker
There are several features of the Docker project that make it convenient to use.
Reproducibility and work in time
On each operating system, that has Docker installed, it is possible to run the image and create the container with the same environment. Windows, MacOS or Linux – is not important, what operating system we use. So if in the developer team the members uses different operating systems, they don’t need to install or fully virtualize another operating system. Simply install Docker and run the container with the desired operating system and tools.
Isolation and speed
Installing and setting any tools in the container does not influence the hosting operating system or other containers. It means that the on one server we can have running in one container a web server and in a second container a database server, and we don’t need to worry about possible influences and conflicts between them. Thanks to that we can set the developing environment quickly with the desired tools and try out alternatives without the endangering the stability of the hosting operating server.
Security
Isolation of the specific components can bring the increased security. At the same time it is a way how to operate older application that are without technical support in isolation.
When you should not use Docker
Every technology is good in some cases and in some other cases it may be a better solution to choose. These are cases that Docker may not be the best solution.
Complicity and speed
If the application is too complicated and we need it to be as fast as possible, Docker is not the best idea. It adds layers, that stands between the hosting operating system and application, which naturally slows the speed of the application. Simply put, if some application needs more resources and is more difficult to horizontaly scale it.
Application with graphic user interface (GUI)
If you develop an application that is managed in the graphical interface with cursor (so not entirely via command line), Docker is not a suitable tool. In this case it is adviced to use a computer with the desired operating system or virtualize the operating system.
Installing Docker
We will show you the installation of the project Docker on operating system Ubuntu 20.04. Installation for Windows and MacOS is done via graphical interface Docker Desktop, which will guide you trough the whole process of installation. Commands of project Docker will work on each operating system the same.
Firstly we need to secure the update of the packages. Install them all in two commands in one go.
sudo apt update && sudo apt upgrade
If the system is finds updated packages, it will ask, if you want to install them:
Do you want to continue? [Y/n]
Press the key y to start the update or press n, to cancel the update. Then press the Enter key.
For the installation of project Docker we use the official script, that will simplify the installation in the terminal to 2 commands:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
From now on we can run the containers and use all other tools provided by the project Docker.
If you would like to use Docker as a user without the root rights, you should consider adding the user to the “docker” group for example like this:
sudo usermod -aG docker užívateľ
Summary
We have defined, what the Docker is, when you should use it and when not to. We have installed the Docker and shown you, how to easily and quickly run the Linux distribution environment Ubuntu.