Learn Docker Part 1: Basics

https://towardsdatascience.com/learn-enough-docker-to-be-useful-b7ba70caeb4b
  • Transfer
  • Tutorial
Application containment technologies are widely used in software development and data analysis. These technologies help make applications more secure, make them easier to deploy, and improve their ability to scale. The growth and development of containerization technologies can be considered one of the most important trends of our time.

Docker is a platform designed to develop, deploy, and launch applications in containers. The word "Docker" has recently become something of a synonym for the word "containerization." And if you are not yet using Docker, but at the same time you are working or are going to work in the areas of application development or data analysis, then Docker is something that you will certainly meet in the future.

Part 1: Basics
Part 2: Terms and Concepts
Part 3: Dockerfile files If you do not yet know what a Docker is, now you have a chance to take the first step towards understanding this platform. Namely, having mastered this material, you will understand the basics of Docker and simultaneously prepare a pizza.

image



Metaphors and Docker


We are constantly confronted with metaphors. If you look into Ozhegov’s dictionary, it will turn out that the metaphor is “a hidden figurative comparison, likening one thing to another.” Metaphors help us grasp the essence of new phenomena for us. For example, virtual containers can be compared to ordinary plastic containers. Such a comparison, by comparing the properties of ordinary containers already known to us with the properties of virtual containers, will help you first get to know them, and then understand their essence.


Container

As you understand, we are going to start talking about Docker with the concept of “container”.

Container


Like a regular plastic container, the Docker container has the following characteristics:

  1. You can store something in it. Something can be either in the container or outside it.
  2. It can be transferred. The Docker Container can be used locally, on a colleague’s computer, on a cloud service provider’s server (such as AWS). This makes Docker containers similar to ordinary containers, in which, for example, they carry various lovely trinkets when moving to a new house.
  3. It is convenient to put something into the container and it is convenient to take something out of it. An ordinary container has a lid on the latches, which must be removed in order to put something in the container or take something out of it. Docker containers have something similar that represents their interface, that is, mechanisms that allow them to interact with the outside world. For example, the container has ports that can be opened so that the application running in the container can be accessed from the browser. You can work with the container using command line tools.
  4. If you need a container, you can order it in the online store. An empty container can be bought, for example, on the Amazon website. Containers come to this store from manufacturers who make them in huge quantities using molds. In the case of Docker containers, what can be compared to a mold, namely the image of the container, is stored in a special repository. If you need a container, you can download the corresponding image from the repository, and using it, create this container.

Of course, plastic containers, unlike Docker containers, will not be sent to you for free, and when you receive them, they will be empty. But in Docker containers there is always something interesting.

Alive organisms


Another approach to thinking about Docker containers is to compare them with specimens of living organisms. An “instance” is something that exists in some form. This is not just a code. This is the code that caused the existence of something larger than himself, something, so to speak, alive. Like other living organisms, instances of containers are born, live and die.


Monster, brought to life

Docker containers are Docker images brought to life.

Software


Docker containers can be compared not only with conventional containers or with living organisms. They can be compared with the programs. After all, containers are programs. And, at a fundamental level, a container is a set of instructions that runs on a certain processor, processing some data.


A container is a program

During the execution of a Docker container inside it, a program is usually executed. It performs some actions in the container, that is, it does something useful.

For example, the code that runs in the Docker container may have sent the text you are reading to your computer. It is also possible that the code running in the Docker container accepts the voice commands that you give to Amazon Alexa, and converts them into instructions for some other programs running in other containers.

Thanks to the use of Docker, you can simultaneously run multiple containers on the same computer. And, like any other program, Docker containers can be started, stopped, deleted. You can explore their contents and create them.

Docker concepts


▍Virtual machines


The predecessors of Docker containers were virtual machines. A virtual machine, like a container, isolates an application and its dependencies from the external environment. However, Docker containers have advantages over virtual machines. So, they consume less resources, they are very easy to carry, they start faster and come to a working state. In this article you can find a detailed comparison of containers and virtual machines.

▍ Docker Container Image


Above, we have already talked about "images." What it is? Good question. The fact that in Docker terminology is called “image”, or, in English, “image”, is not at all the same as, for example, a photograph (this is one of the meanings of the word “image”).


Docker images are not photographs

Docker container images can be compared with drawings, with cookie cutters, or with molds for making plastic products. Images are immutable patterns that are used to create identical containers.


Docker container images look like cookie

cutters. The Docker container image contains the image of the base operating system, application code, and the library on which it depends. All this is packaged as a single entity, on the basis of which you can create a container.

DoDockerfile file


The Dockerfile file contains a set of instructions, following which Docker will build an image of the container. This file contains the description of the base image, which will be the original layer of the image. Among the popular official base images are python , ubuntu , alpine .

Additional layers can be added to the container image, on top of the base image. This is done in accordance with the instructions from Dockerfile. For example, if it Dockerfiledescribes an image that you plan to use for solving machine learning problems, then it may contain instructions for including the NumPy, Pandas, and Scikit-learn libraries into the intermediate layer.

And finally, the image can contain, on top of all the others, another thin layer, the data stored in which is amenable to change. This is a small volume layer containing a program that you plan to run in a container.

▍Container Docker


In order to launch the container, we need, firstly, the image of the container, and secondly, the environment in which Docker is installed, able to understand the command of the form docker run image_name. This command creates a container from the image and runs it.

Контейнер Container repository


If you want to enable other people to create containers based on your image, you can send this image to the cloud storage. The largest repository of this kind is the Docker Hub repository . It is used when working with Docker by default.

We have already discussed quite a lot. It's time to put it all together and compare the work with Docker containers with pizza cooking.

Cooking with Docker



Ready pizza is a container

  • The pizza cooking recipe is a file Dockerfile. He tells us what needs to be done in order to achieve the goal, that is, to get a working container.
  • The ingredients that make up the pizza are the layers of the container image. For our pizza will need a cake, sauce and cheese.

If you put a recipe and ingredients on the table, it turns out that in one place everything you need to make pizza is collected. All this can be compared with the image of the Docker container.
From the recipe ( Dockerfile) you can find out what sequence of actions you need to perform in order to prepare a pizza:

  • The cake is already ready for use, we are not changing it. It can be compared to the base image of Ubuntu OS. This is the bottom layer of the image, it is added to the image first.
  • Then add cheese to the cake. This is the same as adding a second layer to the image in the form of some external library like NumPy.
  • Then, on top of the cheese, add the sauce. This is the application code that should run in the container.

Now it's time to cook the pizza in the oven.


The oven is the Docker platform. The oven

in which pizza is cooked resembles the Docker platform. The oven is installed in the kitchen, it can be used to cook food. In the same way, Docker is installed on the computer in order to “prepare” the containers.

The oven, if it is electric, is turned on by turning the temperature regulator knob. A teamdocker run image_nameis something like a temperature controller, the “rotation” of which leads to the fact that the system creates and launches a container.

Ready pizza is the Docker container.

And eating pizza means using an application running in a container.

As with the preparation of pizza, the preparation for the operation of the Docker containers takes some time, but in the final, and in both cases, something tasty turns out.

Results


Here we have, at a conceptual level, the basics of Docker. Hopefully, the comparisons given here have helped you understand what a Docker is, and feel the value of metaphors in mastering new technologies.

Dear readers! This post is a translation of the first article in the Docker tutorial series. According to the author, it is planned to release 5 such materials in total. The second , third and fourth parts are ready . Tell us, is it worth translating the following articles in this series?

Only registered users can participate in the survey. Sign in , please.

Do I need to translate a cycle of training materials on Docker?


Also popular now: