Docker egyszerűsítve: gyakorlati útmutató az abszolút kezdők számára

Akár a DevOps-ban tervezi kezdeni, akár már foglalkozik vele, ha az önéletrajzában nem szerepel a Docker, akkor kétségtelenül ideje elgondolkodnia rajta, mivel a Docker az egyik kritikus képesség mindenki számára, aki a DevOps arénába kerül.

Ebben a bejegyzésben mindent megteszek annak érdekében, hogy a lehető legegyszerűbb módon elmagyarázzam Dockert.

Mielőtt mélyen merülnénk és elkezdjük felfedezni a Dockert, vessünk egy pillantást arra, hogy milyen témákat fogunk bemutatni ennek a kezdő útmutatónak a részeként.

  • Mi az a Docker?
  • A problémát, amelyet Docker megold
  • A Docker használatának előnyei és hátrányai
  • A Docker alapvető elemei
  • Docker terminológia
  • Mi az a Docker Hub?
  • Docker Editions
  • A Docker telepítése
  • Néhány alapvető Docker-parancs a kezdéshez
  • Összecsomagolás

Kezdjük azzal, hogy megértsük: Mi az a Docker?

Egyszerűbben fogalmazva: a Docker egy szoftverplatform, amely leegyszerűsíti az alkalmazások felépítését, futtatását, kezelését és terjesztését. Ezt a számítógép operációs rendszerének virtualizálásával teszi, amelyre telepítve és fut.

A Docker első kiadása 2013-ban jelent meg.

A Docker fejlesztése a GO programozási nyelv segítségével történt.

A Docker által kínált funkcionalitás gazdag kínálatát tekintve a világ vezető szervezetei és egyetemei, például a Visa, a PayPal, a Cornell Egyetem és az Indiana Egyetem (csak néhányat említve) széles körben elfogadták működésüket alkalmazások a Docker segítségével.

Most próbáljuk megérteni a problémát, és a megoldást, amelyet a Docker kínál

A probléma

Tegyük fel, hogy három különböző Python-alapú alkalmazásod van, amelyeket egyetlen kiszolgálón tervez hosztolni (ami lehet fizikai vagy virtuális gép).

Ezen alkalmazások mindegyike a Python különböző verzióit használja, valamint a kapcsolódó könyvtárak és függőségek alkalmazásonként eltérnek.

Mivel nem lehet ugyanazon a gépen telepíteni a Python különböző verzióit, ez megakadályozza, hogy mindhárom alkalmazást ugyanazon a számítógépen tároljuk.

A megoldás

Nézzük meg, hogyan tudnánk megoldani ezt a problémát a Docker használata nélkül. Egy ilyen forgatókönyv szerint megoldhatnánk ezt a problémát akár három fizikai géppel, akár egyetlen fizikai géppel, amely elég nagy ahhoz, hogy három virtuális gépet üzemeltessen és futtasson rajta.

Mindkét lehetőség lehetővé tenné számunkra, hogy a Python különböző verzióit telepítsük mindegyik gépre, a hozzájuk tartozó függőségekkel együtt.

Függetlenül attól, hogy melyik megoldást választjuk, a hardver beszerzésével és karbantartásával kapcsolatos költségek meglehetősen drágák.

Most nézzük meg, hogyan lehet a Docker hatékony és költséghatékony megoldás erre a problémára.

Ennek megértéséhez meg kell vizsgálnunk, hogyan működik pontosan a Docker.

A gépet, amelyre a Docker telepítve van és fut, általában egyszerűen Docker Hostnak vagy Hostnak nevezzük.

Tehát, amikor egy alkalmazást tervez telepíteni a gazdagépre, az létrehoz egy logikai entitást az alkalmazás tárolására. A Docker terminológiájában pontosabban fogalmazva ezt a logikai entitást Containernek vagy Docker Container-nek hívjuk.

A Docker Container nem telepített és fut egyetlen operációs rendszert sem. De lenne egy virtuális másolata a folyamattáblázatnak, a hálózati interfész (ek) nek és a fájlrendszer csatlakozási pont (ok) nak. Ezeket annak a gazdagépnek az operációs rendszerétől örökölték, amelyen a tárolót üzemeltetik és futnak.

Míg a gazdagép operációs rendszerének rendszermagja meg van osztva az összes rajta futó tárolóval.

Ez lehetővé teszi, hogy minden tartályt el lehessen különíteni az ugyanazon gazdaszervezetben lévő többi tárolótól. Így több, különböző alkalmazási követelményekkel és függőséggel rendelkező tárolót támogat ugyanazon a gazdagépen történő futtatásra, amennyiben azonos operációs rendszer követelményekkel rendelkeznek.

Annak megértéséhez, hogy a Docker milyen előnyös volt a probléma megoldásában, olvassa el a következő szakaszt, amely a Docker használatának előnyeit és hátrányait taglalja.

Röviden: a Docker a hardverkomponensek virtualizálása helyett virtualizálná a gazdagép operációs rendszerét, amelyre telepítve van és fut.

A Docker használatának előnyei és hátrányai

A Docker használatának előnyei

Az alábbiakban felsoroljuk a Docker használatának néhány fő előnyét:

  • A Docker több, különböző alkalmazási követelményekkel és függőséggel rendelkező alkalmazást támogat, amelyeket ugyanazon a gazdagépen kell együtt tárolni, amennyiben azonos operációs rendszer követelményekkel rendelkeznek.
  • Tárolás optimalizált. Nagyszámú alkalmazás tárolható ugyanazon a gazdagépen, mivel a tárolók általában kevés megabájt méretűek és nagyon kevés lemezt foglalnak magukba.
  • Robusztus. A konténeren nincs operációs rendszer telepítve. Így nagyon kevés memóriát fogyaszt, mint egy virtuális gép (amelyre egy teljes operációs rendszer lenne telepítve és futna). Ez is csak néhány másodpercre csökkenti az indítási időt, szemben a virtuális gép indításához szükséges pár perccel.
  • Csökkenti a költségeket. A Docker kevésbé igényes, ha a futtatásához szükséges hardverről van szó.

A Docker használatának hátrányai

  • A különböző operációs rendszer követelményekkel rendelkező alkalmazások nem tárolhatók együtt ugyanazon a Docker Hoston. Tegyük fel például, hogy 4 különböző alkalmazásunk van, amelyek közül 3 alkalmazáshoz Linux-alapú, a másikhoz Windows-alapú operációs rendszer szükséges. Ilyen esetekben a Linux-alapú operációs rendszert igénylő 3 alkalmazás egyetlen Docker Hoston, míg a Windows-alapú operációs rendszert igénylő alkalmazás egy másik Docker Hoston kell hosztolnia.

A Docker alapkomponensei

A Docker Engine a Docker egyik alapeleme. Felelős a Docker platform általános működéséért.

A Docker Engine egy kliens-szerver alapú alkalmazás, amely 3 fő összetevőből áll.

  1. szerver
  2. REST API
  3. Ügyfél

A szerver futtat egy dockert (Docker Daemon) néven ismert démonot , ami nem más, mint egy folyamat. Felelős a Docker Képek, Tárolók, Hálózatok és Kötetek létrehozásáért és kezeléséért a Docker platformon.

A REST API meghatározza, hogy az alkalmazások miként léphetnek kapcsolatba a szerverrel, és utasítja a feladat elvégzésére.

Az ügyfél nem más, mint egy parancssori felület, amely lehetővé teszi a felhasználók számára, hogy a parancsok használatával kölcsönhatásba lépjenek a Dockerrel .

Docker terminológia

Vessünk egy gyors pillantást a Dockerhez kapcsolódó terminológiára.

A Docker Images és a Docker Containers a két alapvető dolog, amellyel naponta találkozni fog, amikor a Dockerrel dolgozik .

Egyszerűen fogalmazva: a Docker Image egy sablon, amely tartalmazza az alkalmazást és az alkalmazás Docker futtatásához szükséges összes függőséget.

Másrészt, amint azt korábban elmondtuk, a Docker Container logikai entitás. Pontosabban fogalmazva: a Docker Image futó példánya.

Mi az a Docker Hub?

A Docker Hub a hivatalos online adattár, ahol megtalálhatja az összes rendelkezésünkre álló Docker képet.

Docker Hub also allows us to store and distribute our custom images as well if we wish to do so. We could also make them either public or private, based on our requirements.

Please Note: Free users are only allowed to keep one Docker Image as private. If we wish to keep more than one Docker Image as private, we need to subscribe to a paid subscription plan.

Docker Editions

Docker is available in 2 different editions, as listed below:

  • Community Edition (CE)
  • Enterprise Edition (EE)

The Community Edition is suitable for individual developers and small teams. It offers limited functionality, in comparison to the Enterprise Edition.

The Enterprise Edition, on the other hand, is suitable for large teams and for using Docker in production environments.

The Enterprise Edition is further categorized into three different editions, as listed below:

  • Basic Edition
  • Standard Edition
  • Advanced Edition

Installing Docker

One last thing that we need to know before we go ahead and get our hands dirty with Docker is actually to have Docker installed.

Below are the links to the official Docker CE installation guides. You can follow these guides to install Docker on your machine, as they are simple and straightforward.

  • CentOS Linux
  • Debian Linux
  • Fedora Linux
  • Ubuntu Linux
  • Microsoft Windows
  • MacOS

Want to skip installation and head off straight to practicing Docker?

Just in case you are feeling too lazy to install Docker, or you don’t have enough resources available on your computer, you need not have to worry — here’s the solution to your problem.

You can head over to Play with Docker, which is an online playground for Docker. It allows users to practice Docker commands immediately, without having to install anything on your machine. The best part is it’s simple to use and available free of cost.

Docker Commands

Now it’s time to get our hands dirty with Docker commands, for which we all have been waiting till now.

docker create

The first command which we will be looking at is the docker create command.

This command allows us to create a new container.

The syntax for this command is as shown below:

docker create [options] IMAGE [commands] [arguments]

Please Note: Anything enclosed within the square brackets is optional. This is applicable to all the commands that you would see on this guide.

Some of the examples of using this command are shown below:

$ docker create fedora
02576e880a2ccbb4ce5c51032ea3b3bb8316e5b626861fc87d28627c810af03

In the above example, the docker create command would create a new container using the latest Fedora image.

Before creating the container, it will check if the latest official image of the Fedora is available on the Docker Host or not. If the latest image isn’t available on the Docker Host, it will then go ahead and download the Fedora image from the Docker Hub before creating the container. If the Fedora image is already present on the Docker Host, it will make use of that image and create the container.

If the container was created successfully, Docker will return the container ID. For instance, in the above example 02576e880a2ccbb4ce5c51032ea3b3bb8316e5b626861fc87d28627c810af03 is the container ID returned by Docker.

Each container has a unique container ID. We refer to the container using its container ID for performing various operations on the container, such as starting, stopping, restarting, and so on.

Now, let us refer to another example of docker create command, which has options and commands being passed to it.

$ docker create -t -i ubuntu bash
30986b73dc0022dbba81648d9e35e6e866b4356f026e75660460c3474f1ca005

In the above example, the docker create command creates a container using the Ubuntu image (As stated earlier, if the image isn’t available on the Docker Host, it will go ahead and download the latest image from the Docker Hub before creating the container).

The options -t and -i instruct Docker to allocate a terminal to the container so that the user can interact with the container. It also instructs Docker to execute the bash command whenever the container is started.

docker ps

The next command we will look at is the docker ps command.

The docker ps command allows us to view all the containers that are running on the Docker Host.

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES30986b73dc00 ubuntu "bash" 45 minutes ago Up About a minute elated_franklin

It only displays the containers that are presently running on the Docker Host.

If you want to view all the containers that were created on this Docker Host, irrespective of their current status, such as whether they are running or exited, then you would need to include the option -a, which in turn would display all the containers that were created on this Docker Host.

$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES30986b73dc00 ubuntu “bash” About an hour ago Up 29 minutes elated_franklin02576e880a2c fedora “/bin/bash” About an hour ago Created hungry_sinoussi

Before we proceed further, let’s try to decode and understand the output of the docker ps command.

CONTAINER ID: A unique string consisting of alpha-numeric characters, associated with each container.

IMAGE: Name of the Docker Image used to create this container.

COMMAND: Any application specific command(s) that needs to be executed when the container is started.

CREATED: This shows the time elapsed since this container has been created.

STATUS: This shows the current status of the container, along with the time elapsed, in its present state.

If the container is running, it will display as Up along with the time period elapsed (for example, Up About an hour or Up 3 minutes).

If the container is stopped, then it will display as Exited followed by the exit status code within round brackets, along with the time period elapsed (for example, Exited (0) 3 weeks ago or Exited (137) 15 seconds ago, where 0 and 137 are the exit codes).

PORTS: This displays any port mappings defined for the container.

NAMES: Apart from the CONTAINER ID, each container is also assigned a unique name. We can refer to a container either using its container ID or its unique name. Docker automatically assigns a unique silly name to each container it creates. But if you want to specify your own name to the container, you can do that by including the — — name (double hyphen name) option to the docker create or the docker run (we will look at the docker run command later) command.

I hope this gives you a better understanding of the output of the docker ps command.

docker start

The next command we will look at, is the docker start command.

This command starts any stopped container(s).

The syntax for this command is as shown below:

docker start [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

We can start a container either by specifying the first few unique characters of its container ID or by specifying its name.

Some of the examples of using this command are shown below:

$ docker start 30986

In the above example, Docker starts the container beginning with the container ID 30986.

$ docker start elated_franklin

Whereas in this example, Docker starts the container named elated_franklin.

docker stop

The next command on the list is the docker stop command.

This command stops any running container(s).

The syntax for this command is as shown below:

docker stop [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

It is similar to the docker start command.

We can stop the container either by specifying the first few unique characters of its container ID or by specifying its name.

Some of the examples of using this command are shown below:

$ docker stop 30986

In the above example, Docker will stop the container beginning with the container ID 30986.

$ docker stop elated_franklin

Whereas in this example, Docker will stop the container named elated_franklin.

docker restart

The next command we will look at is the docker restart command.

This command restarts any running container(s).

The syntax for this command is as shown below:

docker restart [options] CONTAINER ID/NAME [CONTAINER ID/NAME…]

We can restart the container either by specifying the first few unique characters of its container ID or by specifying its name.

Some of the examples of using this command are shown below:

$ docker restart 30986

In the above example, Docker will restart the container beginning with the container ID 30986.

$ docker restart elated_franklin

Whereas in this example, Docker will restart the container named elated_franklin.

docker run

The next command we will be looking at is the docker run command.

This command first creates the container, and then it starts the container. In short, this command is a combination of the docker create and the docker start command.

The syntax for this command is as shown below:

docker run [options] IMAGE [commands] [arguments]

It has a syntax similar to that of the docker create command.

Some of the examples of using this command are shown below:

$ docker run ubuntu
30fa018c72682d78cf168626b5e6138bb3b3ae23015c5ec4bbcc2a088e67520

In the above example, Docker will create the container using the latest Ubuntu image and then immediately start the container.

If we execute the above command, it would start the container and immediately stop it — we wouldn’t get any chance to interact with the container at all.

If we want to interact with the container, then we need to specify the options: -it (hyphen followed by i and t) to the docker run command presents us with the terminal, using which we could interact with the container by typing in appropriate commands. Below is an example of the same.

$ docker run -it ubuntu
root@e4e633428474:/#

In order to come out of the container, you need to type exit in the terminal.

docker rm

Moving on to the next command — if we want to delete a container, we use the docker rm command.

The syntax for this command is as shown below:

docker rm [options] CONTAINER ID/NAME [CONTAINER ID/NAME...]

Some of the examples of using this command are shown below:

$ docker rm 30fa elated_franklin

In the above example, we are instructing Docker to delete 2 containers within a single command. The first container to be deleted is specified using its container ID, and the second container to be deleted is specified using its name.

Please Note: The containers need to be in a stopped state in order to be deleted.

docker images

docker images is the next command on the list.

This command lists out all the Docker Images that are present on your Docker Host.

$ docker images
REPOSITORY TAG IMAGE CREATED SIZEmysql latest 7bb2586065cd 38 hours ago 477MBhttpd latest 5eace252f2f2 38 hours ago 132MBubuntu 16.04 9361ce633ff1 2 weeks ago 118MBubuntu trusty 390582d83ead 2 weeks ago 188MBfedora latest d09302f77cfc 2 weeks ago 275MBubuntu latest 94e814e2efa8 2 weeks ago 88.9MB

Let us decode the output of the docker images command.

REPOSITORY: This represents the unique name of the Docker Image.

TAG: Each image is associated with a unique tag. A tag basically represents a version of the image.

A tag is usually represented either using a word or set of numbers or a combination of alphanumeric characters.

IMAGE ID: A unique string consisting of alpha-numeric characters, associated with each image.

CREATED: This shows the time elapsed since this image has been created.

SIZE: This shows the size of the image.

docker rmi

The next command on the list is the docker rmi command.

The docker rmi command allows us to remove an image(s) from the Docker Host.

The syntax for this command is as shown below:

docker rmi [options] IMAGE NAME/ID [IMAGE NAME/ID...]

Some of the examples of using this command are shown below:

docker rmi mysql

The above command removes the image named mysql from the Docker Host.

docker rmi httpd fedora

The above command removes the images named httpd and fedora from the Docker Host.

docker rmi 94e81

The above command removes the image starting with the image ID 94e81 from the Docker Host.

docker rmi ubuntu:trusty

The above command removes the image named ubuntu, with the tag trusty from the Docker Host.

These were some of the basic Docker commands you will see. There are many more Docker commands to explore.

Wrap-Up

A konténerezés nemrégiben felkeltette a megérdemelt figyelmet, bár régóta létezik. Néhány csúcstechnológiai vállalat, például a Google, az Amazon Web Services (AWS), az Intel, a Tesla és a Juniper Networks saját konténermotorral rendelkezik. Nagyon támaszkodnak rájuk az alkalmazások létrehozásában, futtatásában, kezelésében és terjesztésében.

A Docker egy rendkívül nagy teljesítményű konténeres motor, és sok mindent kínál az alkalmazások hatékony felépítésével, futtatásával, kezelésével és terjesztésével kapcsolatban.

Most látta Dockert nagyon magas szinten. Sokkal többet kell megtudni a Dockerről, például:

  • Docker-parancsok (hatékonyabb parancsok)
  • Docker Images (Készítsen saját egyéni képeket)
  • Docker Networking (Hálózat beállítása és konfigurálása)
  • Docker Services (Ugyanazt a képet használó tárolók csoportosítása)
  • Docker Stack (Grouping services required by an application)
  • Docker Compose (Tool for managing and running multiple containers)
  • Docker Swarm (Grouping and managing one or more machines on which docker is running)
  • And much more…

If you have found Docker to be fascinating, and are interested in learning more about it, then I would recommend that you enroll in the courses which are listed below. I found them to be very informative and straight to the point.

If you are an absolute beginner, then I would suggest you enroll in this course, which has been designed for beginners.

If you have some good knowledge about Docker, and are pretty much confident with the basic stuff and want to expand your knowledge, then I would suggest you should enroll into this course, which is aimed more towards advanced topics related to Docker.

A Docker jövőbiztos képesség, és csak lendületet vesz.

Ha időt és pénzt fektetne be a Docker megtanulásába, nem bánná meg.

Remélem, hogy ezt a bejegyzést informatívnak találta. bátran ossza meg. Ez nekem nagyon sokat jelent.

Búcsúzás előtt…

Maradjunk kapcsolatban, kattintson ide az e-mail cím megadásához (Használja ezt a linket, ha a fenti widget nem jelenik meg a képernyőn).

Nagyon köszönöm, hogy drága időt szánt a bejegyzés elolvasására.

Jogi nyilatkozat: Minden termék- és cégnév a megfelelő tulajdonosok védjegye vagy bejegyzett védjegye. Használatuk nem jelenti azt, hogy támogatnák őket. Lehet, hogy társult linkek találhatók ebben a bejegyzésben.