Monday, 12 July 2021

Docker: Getting started

Introduction
In this article, we be covering a basic introduction to the Docker Tool along with its installation on a Centos 7 system. Docker has become synonymous with containerization of applications in Linux and thousands of applications have successfully been dockerized and deployed in Production since Docker's inception.

History of Docker:
Docker, Inc. is a technology company based in San Francisco. It was founded by French born american Solomon Hykes and start as a PaaS provider called dotCloud. dotCloud leveraged Linux containers and their internal tool used to manage containers was nick-named Docker. In 2013 dotCloud was re branded as Docker.

What is Docker?
To understand what is Docker we must first know what are containers. A container is a special type of process that is isolated from other processes. Containers are assigned resources that no other process can access, and they cannot access any resources not explicitly assigned to them. Docker provides a Runtime and Orchestration Engine to allow users to deploy and manage containers. There are tools available that also allow for the orchestration of containers.

Docker is available in the following main editions:

Enterprise Edition (EE): Paid and supported for 12 months. Provides additional features like certified images, same day support and vulnerability scanning of images.
Community Edition (CE) : Free and supported for 4 months.
Moby: Open-Source upstream project of Docker and breaks Docker down into more modular components

Why should you use Docker?

Dev and Production environment are the same
Bugs in Production can be replicated in Development
Lets you put your environment and configuration into code and deploy it
Allows the same Docker configuration to be used in a variety of environments
Build standards and repeatable processes
Developer Productivity
App Isolation
Server Consolidation

Installing Docker:

Before installing Docker we must install some of the pre-requisite packages as shown below:

yum install -y yum-utils device-mapper-persistent-data lvm2

Now we will add the stable repository for the Docker community edition of the system:

[root@dokcer-test ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror
adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@dokcer-test ~]#

Now that the Docker repository has been configured, we can install Docker CE using yum.

 yum -y install docker-ce

The above command installs the following packages:

===========================================================================================================================================================
 Package                                 Arch                         Version                                 Repository                              Size
===========================================================================================================================================================
Installing:
 docker-ce                               x86_64                       3:19.03.1-3.el7                         docker-ce-stable                        24 M
Installing for dependencies:
 container-selinux                       noarch                       2:2.99-1.el7_6                          extras                                  39 k
 containerd.io                           x86_64                       1.2.6-3.3.el7                           docker-ce-stable                        26 M
 docker-ce-cli                           x86_64                       1:19.03.1-3.el7                         docker-ce-stable                        39 M


After the packages are successfully installed, we'll start the docker service and also enable it so that it starts automatically on boot.

[root@dokcer-test ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-07-30 04:38:00 UTC; 6s ago
     Docs: https://docs.docker.com
 Main PID: 9008 (dockerd)
   CGroup: /system.slice/docker.service
           └─9008 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jul 30 04:37:58 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:58.649760132Z" level=info msg="Creating filesystem xfs on de...emapper
Jul 30 04:37:59 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:59.064964291Z" level=info msg="Successfully created filesyst...emapper
Jul 30 04:37:59 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:59.211113995Z" level=warning msg="[graphdriver] WARNING: the...elease"
Jul 30 04:37:59 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:59.269462315Z" level=info msg="Loading containers: start."
Jul 30 04:37:59 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:59.567854253Z" level=info msg="Default bridge (docker0) is a...ddress"
Jul 30 04:37:59 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:37:59.654696034Z" level=info msg="Loading containers: done."
Jul 30 04:38:00 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:38:00.354472432Z" level=info msg="Docker daemon" commit=74b1e89...19.03.1
Jul 30 04:38:00 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:38:00.355436639Z" level=info msg="Daemon has completed initialization"
Jul 30 04:38:00 dokcer-test.example.com systemd[1]: Started Docker Application Container Engine.
Jul 30 04:38:00 dokcer-test.example.com dockerd[9008]: time="2019-07-30T04:38:00.527177004Z" level=info msg="API listen on /var/run/docker.sock"
Hint: Some lines were ellipsized, use -l to show in full.
[root@dokcer-test ~]#


It is considered best practice to not manage containers directly as the root user. Therefore, I'll add a user named sahil to the docker group and use this user account for running and managing containers on this server.

usermod -aG docker sahil

Let's verify that we can run Docker related commands as the user sahil:

[sahil@docker-test ~]$ docker version
Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:21:07 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       74b1e89
  Built:            Thu Jul 25 21:19:36 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683
[sahil@docker-test ~]$


Conclusion
This concludes our introduction to Docker where we talked about the history of Docker along with it's most popular use cases and also installed Docker on a Centos 7 system.

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...