How to Install and use Docker on CentOS-7.6

How to Install and use Docker on CentOS-7.6

Introduction:

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. In this tutorial, we are going to cover the method to install and use Docker on CentOS 7.6

Installation Procedure:

Use the Below command to check the installed version of OS

[root@linuxhelp ~]# rpm -q centos-release
centos-release-7-6.1810.2.el7.centos.x86_64

Command to Install yum-utils
 [root@linuxhelp ~]# yum install yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirrors.estointernet.in
 * extras: centos.mirrors.estointernet.in
 * updates: centos.mirrors.estointernet.in
base                                                                                  | 3.6 kB  00:00:00     
extras                                                                                | 2.9 kB  00:00:00     
updates                                                                               | 2.9 kB  00:00:00     
(1/4): base/7/x86_64/group_gz                                                         | 153 kB  00:00:04     
(2/4): extras/7/x86_64/primary_db                                                     | 206 kB  00:00:04     
(3/4): updates/7/x86_64/primary_db                                                    | 3.8 MB  00:00:11     
(4/4): base/7/x86_64/primary_db                                                       | 6.1 MB  00:00:12     
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Finished Dependency Resolution
……
……..
Dependencies Resolved
  Verifying  : yum-utils-1.1.31-50.el7.noarch                                                            2/2 
Updated:
  yum-utils.noarch 0:1.1.31-54.el7_8                                                                         
Complete!

Configure Stable repo for docker using below method

[root@linuxhelp ~]# yum-config-manager \
> --add-repo \
> https://download.docker.com/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
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

Then, Enable the Docker-nightly repo

[root@linuxhelp ~]# yum-config-manager --enable docker-ce-nightly
Loaded plugins: fastestmirror, langpacks
========================================== repo: docker-ce-nightly ==========================================
[docker-ce-nightly]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = https://download.docker.com/linux/centos/7/x86_64/nightly
cache = 0
cachedir = /var/cache/yum/x86_64/7/docker-ce-nightly
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
enabled = 1
enablegroups = True
exclude = 
failovermethod = priority
….
….
throttle = 0
timeout = 30.0
ui_id = docker-ce-nightly/x86_64
ui_repoid_vars = releasever,
   basearch
username = 

To Install Docker and Containerd

[root@linuxhelp ~]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.myfahim.com
* extras: mirror.myfahim.com
* updates: mirror.myfahim.com
docker-ce-nightly                                                                     | 3.5 kB  00:00:00     
docker-ce-stable                                                                      | 3.5 kB  00:00:00     
(1/4): docker-ce-nightly/x86_64/updateinfo                                            |   55 B  00:00:00     
(2/4): docker-ce-stable/x86_64/updateinfo                                             |   55 B  00:00:00     
…..
…..
 Verifying  : 3:docker-ce-19.03.12-3.el7.x86_64                                                         2/4 
 Verifying  : containerd.io-1.2.13-3.2.el7.x86_64                                                       3/4 
 Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                        4/4 
Installed:
 containerd.io.x86_64 0:1.2.13-3.2.el7                   docker-ce.x86_64 3:19.03.12-3.el7                  
 docker-ce-cli.x86_64 1:19.03.12-3.el7                  
Dependency Installed:
 container-selinux.noarch 2:2.119.2-1.911c772.el7_8                                                         
Complete!

Use the Below command to download docker-compose

[root@linuxhelp ~]# curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100   638  100   638    0     0    915      0 --:--:-- --:--:-- --:--:--   916
100 11.6M  100 11.6M    0     0   671k      0  0:00:17  0:00:17 --:--:--  623k

Enable the docker service permanently

[root@linuxhelp ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Start the docker service

[root@linuxhelp ~]# systemctl start docker

Command to check docker service status

[root@linuxhelp ~]# 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 Thu 2020-08-13 16:27:38 IST; 9s ago
     Docs: https://docs.docker.com
 Main PID: 67355 (dockerd)
    Tasks: 8
   Memory: 35.1M
   CGroup: /system.slice/docker.service
           └─67355 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

…..
…..
Aug 13 16:27:38 linuxhelp dockerd[67355]: time="2020-08-13T16:27:38.712035370+05:30" level=info msg="A...ock"
Aug 13 16:27:38 linuxhelp systemd[1]: Started Docker Application Container Engine.
Hint: Some lines were ellipsized, use -l to show in full.

Test the Docker engine with hello-world

[root@linuxhelp ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

With this, method to install and use Docker on CentOS 7.6 comes to end.

FAQ
Q
5) Do I lose my data when the container exits?
A
Any data that your application writes to disk gets preserved in its container until you explicitly delete the container. The file system for the container persists even after the container halts.
Q
4) What is Docker Image?
A
A Docker image packs up the application and environment required by the application to run
Q
3) What is Docker Container?
A
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Q
2) What are the repositories use to install Docker?
A
The repositories to install Docker
*docker-ce.repo
*docker-ce-nightly
Q
1) What is Docker?
A
Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers.
It allows the users to manage the multi-container application with all of its dependencies in a single file