How To Install and Use Docker Engine on CentoS 8 Tutorial (Step by Step)

How to Install and use Docker Engine on CentOS 8. In this tutorial we will introduce Docker Engine with it’s main advantages then move onto installation phase. We will also explain some basic Docker commands that are used to manage the Docker containers.

With businesses moving workloads to clouds, it is becoming essential to adapt the concept of containerization. The containerization market dominated by Docker enables organizations to deploy applications in containers with other configuration files, libraries, dependencies, etc.

What is Docker?

Docker is an open source platform that separates applications from infrastructure and makes it easier to create, deploy, and run applications faster. Additionally, it allows you to run different containers on a given host.

Today, 2/3 of companies run applications in containers instead of virtual machines. It is because containers allow applications to be deployed, patched, or scaled quickly to multiple different operating systems and platforms.

Containers are lightweight compared to virtual machines and comprise everything (including libraries and other dependencies packed in one) needed to run an application smoothly and faster.

ING, Paypal, ADP, and Spotify are a few high profile companies that use Docker. Also, Docker adoption is gaining momentum in the IT world. Have you ever wondered why it is growing that fast? Let us discuss some of its advantages that will convince you how Docker is better and more useful for businesses moving to cloud environments.

Benefits of Docker

Docker allows the use of local containers for continuous integration and continuous delivery (CI/CD) workflows. It helps developers to write and run codes faster. Further, it is a lightweight and cost effective platform compared to other hypervisor based virtual machines.

If you are looking for a perfect solution for small and medium deployments, look no further. There are more advantages of using Docker, including:

Docker virtualization

Docker a platform as a service (PaaS) that hosts products that use OS level virtualization to deliver software in packages called containers. There is free and premium packages. The software that hosts the containers is called Docker Engine.

Rapid Deployment

It hardly takes any time to deploy applications with Docker. It is generally because the docker provides a standardized working environment for developers and creates a container for each and every process. Also, the applications do not boot into an OS, thus saving a lot of your time.

Additionally, you do not require to set up a new environment with Docker. All you require is downloading the Docker image to run applications in multiple environments. Another feature that makes the deployment faster is each container has minimal runtime requirements for the application.

Isolation

Because docker containers are totally independent that means the stages of your development lifecycle will work exactly the same as it moves through testing and most likely to your users.

Supports Multi Cloud Platforms

Another key benefit of Dockers is portability. Over many years, cloud computing providers, such as Google Compute Platform (GCP), Amazon Web Services (AWS), Microsoft Azure, etc., have been embracing Docker and its support.

After testing the containerized application, you are allowed to deploy them to any other system or run it inside an Amazon EC2 instance, Google Compute Engine instance, or VirtualBox, making sure that the host operating system supports Docker.

Security

Docker ensures that each application running on the container is isolated and cannot look into the processes of one another. Thus, granting full control over the management and traffic flow. It ensures that each application and other configuration files, libraries, dependencies, etc., packed together as one in the container is secure.

Performance

Unlike virtual machines, Docker containers do not contain an operating system, i.e., they have a small footprint and can be created and deployed faster.

Support for remote connections using SSH

Follow this post, to next show you how to install and use Docker Engine on CentOS 8.

Install Docker Engine CentOS 8

Prerequisites

Docker is available in two versions:

 

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

 

In this guide we will show how to Install and use Docker Engine CE (Community Edition) on CentOS 8 Server.

  • A root user or a user with sudo privileges.

Create a Docker Engine Repo

By default, the Docker Engine package is not available in the CentOS default repository. So you will need to create the Docker CE repo on your system.

You can create it using the following command:

				
					dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
				
			

Once the Docker repo is created, run the following command to install Docker Engine on CentOS 8.

				
					dnf install docker-ce -y
				
			

After the successfull installation, start the Docker service and enable it to start at system reboot:

				
					systemctl start docker
systemctl enable docker
				
			

To check the status of the Docker service, run the following command:

				
					systemctl status docker
				
			

You will get the following output:

				
					● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-06-13 12:41:30 UTC; 4s ago
     Docs: https://docs.docker.com
 Main PID: 24753 (dockerd)
    Tasks: 8
   Memory: 33.9M
   CGroup: /system.slice/docker.service
           └─24753 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Jun 13 12:41:29 centos8 dockerd[24753]: time="2022-06-13T12:41:29.819964284Z" level=error msg="Failed to built-in GetDriver graph btrfs /var/>
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.090546750Z" level=warning msg="Your kernel does not support cgroup blkio we>
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.090623022Z" level=warning msg="Your kernel does not support cgroup blkio we>
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.090995662Z" level=info msg="Loading containers: start."
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.522076022Z" level=info msg="Default bridge (docker0) is assigned with an IP>
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.689262549Z" level=info msg="Loading containers: done."
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.713645864Z" level=info msg="Docker daemon" commit=a89b842 graphdriver(s)=ov>
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.713769074Z" level=info msg="Daemon has completed initialization"
Jun 13 12:41:30 centos8 systemd[1]: Started Docker Application Container Engine.
Jun 13 12:41:30 centos8 dockerd[24753]: time="2022-06-13T12:41:30.771949354Z" level=info msg="API listen on /var/run/docker.sock"

				
			

To verify the Docker package information, run the following command:

				
					docker version
				
			

You should get the following output:

				
					Client: Docker Engine - Community
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:03:11 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:29 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
  GitCommit:        10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc:
  Version:          1.1.2
  GitCommit:        v1.1.2-0-ga916309
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

				
			

Create Hello World Container Using Docker

At this point, Docker is installed and running. Now, its time to create and run your first container. We will use the hello world container to test the Docker.

Run the following command to launch the hello world container:

				
					docker run hello-world
				
			

This command will download the hello world Docker image and start it as shown below:

				
					latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:80f31da1ac7b312ba29d65080fddf797dd76acfb870e677f390d5acba9741b17
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/

				
			

Once the Hello World container is started, you can verify the Docker container using the following command:

				
					docker ps -a
				
			

You should see the following output:

				
					CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
8b68917a5943   hello-world   "/hello"   34 seconds ago   Exited (0) 33 seconds ago             stoic_shockley

				
			

Working with Docker

In this section of how to install and use Docker Engine on CentOS 8, we will show you how to use Docker commands to interact with Docker container and manage them.

To search for any Docker image, use the following syntax:

				
					docker search image-name
				
			

For example, to search for a centos image, run the following command:

				
					docker search centos
				
			

You will get a list of all centos images in the following output:

				
					NAME                                         DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
centos                                       The official build of CentOS.                   7183      [OK]       
centos/systemd                               systemd enabled base container.                 108                  [OK]
centos/mysql-57-centos7                      MySQL 5.7 SQL database server                   95                   
kasmweb/centos-7-desktop                     CentOS 7 desktop for Kasm Workspaces            20                   
centos/redis-32-centos7                      Redis in-memory data structure store, used a…   6                    
kasmweb/core-centos-7                        CentOS 7 base image for Kasm Workspaces         3                    
continuumio/centos5_gcc5_base                                                                3                    
couchbase/centos7-systemd                    centos7-systemd images with additional debug…   1                    [OK]
spack/centos7                                CentOS 7 with Spack preinstalled                1                    
spack/centos-stream                                                                          0                    
couchbase/centos-72-jenkins-core                                                             0                    
fnndsc/centos-python3                        Source for a slim Centos-based Python3 image…   0                    [OK]
couchbase/centos-72-java-sdk                                                                 0                    
couchbase/centos-69-sdk-build                                                                0                    
couchbase/centos-70-sdk-build                                                                0                    
datadog/centos-i386                                                                          0                    
spack/centos6                                CentOS 6 with Spack preinstalled                0                    
ibmcom/fhe-toolkit-centos-amd64              The IBM Fully Homomorphic Encryption (FHE) T…   0                    
starlingx/stx-centos                         StarlingX centos                                0                    
ibmcom/fhe-toolkit-centos                    The IBM Fully Homomorphic Encryption (FHE) T…   0                    
apache/couchdbci-centos                      Apache CouchDB CI CentOS                        0                    
silintl/openldap                             OpenLDAP base image on Centos 6                 0                    [OK]
bitnami/centos-extras-base                                                                   0                    
bitnami/centos-base-buildpack                Centos base compilation image                   0                    [OK]
couchbase/centos-69-sdk-nodevtoolset-build                                                   0                    

				
			

From the above list, download the centos image using the following command:

				
					docker pull centos:latest
				
			

This will download the CentOS image from the Docker Hub registry:

				
					latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest
				
			

You can verify the downloaded image using the following command:

				
					docker images
				
			

You will get the following output:

				
					REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    feb5d9fea6a5   8 months ago   13.3kB
centos        latest    5d0da3dc9764   9 months ago   231MB

				
			

To create container from the downloaded CentOS image, run the following command:

				
					docker run -it centos
				
			

This will create a container from the CentOS image and connect to the container shell as shown below:

				
					[root@2f932f77d07b /]#
				
			

To verify the container version, run the following command:

				
					[root@2f932f77d07b /]# cat /etc/redhat-release 
				
			

You should see the following output:

				
					CentOS Linux release 8.4.2105
				
			

Now, run the following command to exit from the CentOS container:

				
					[root@2f932f77d07b /]# exit
				
			

To create a create a container from the CentOS image and start it in background, run the following command:

				
					docker run -dit centos
				
			

You can now verify the running container using the following command:

				
					docker ps
				
			

You should see the running container in the following output:

				
					CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS         PORTS     NAMES
8aa052c4d81a   centos    "/bin/bash"   6 seconds ago   Up 5 seconds             practical_sanderson
				
			

How to Manage Docker Container

In this section, we will show you how to manage Docker container.

To start, stop or pause the Docker container, use the following syntax:

				
					docker start/stop/pause container-id
				
			

For example, to start the CentOS container, run the following command:

				
					docker start 8aa052c4d81a
				
			

To stop the CentOS container, run the following command:

				
					docker stop 8aa052c4d81a
				
			

To pause the CentOS container, run the following command:

				
					docker pause 8aa052c4d81a
				
			

To remove the stopped container, run the following command:

				
					docker container rm 8aa052c4d81a
				
			

If you want to stop all running containers, run the following command:

				
					docker container stop $(docker container ls -aq)
				
			

If you want to remove all stopped containers, run the following command:

				
					docker container rm $(docker container ls -aq)
				
			

To remove the unused Docker images and containers, run the following command:

				
					docker system prune -a
				
			

How to Install and use Docker Engine on CentOS 8 Conclusion

In this post, we will show you how to install Docker Engine on CentOS 8 server. We also explained how to interact with Docker with different commands. I hope this guide will be useful to manage your Docker container.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x