Table of Contents

How to Install Docker on CentOS 8

Last updated: June 11,2020

Introduction

Docker is an open-source tool that allows you to create, test and deploy applications inside containers. It has become most popular due to the portability to run applications anywhere irrespective of the host operating system. It uses OS-level virtualization to deliver software in packages called containers. A container is a lightweight, standalone, executable package of software that includes everything needed to run an application. The container allows you to package up an application with libraries and other dependencies, and deploy it as one package.

Docker is available in two versions.

  1. Docker Community Edition
  2. Docker Enterprise Edition.

In this tutorial, we will show you how to install Docker CE on CentOS 8.

 Prerequisites

  •  A server running CentOS 8.
  • A root password is setup on your server.

Disable SELinux

By default, SELinux is enabled in CentOS 8. So you will need to disable the SELinux to allow Docker containers to work internally.

You can disable it by editing /etc/selinux/config file:

nano /etc/selinux/config

Change the following line:

SELINUX=disabled

Save and close the file then restart your system to apply the changes.

Add Docker CE Repository

By default, Docker is not officially supported on RHEL 8 / CentOS 8 as it has been replaced with Red Hat tools, buildah and podman.

So you will need to add Docker CE official repository in your system.

You can enable the Docker CE repository using the following command:

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

Once the repository is enabled, you can proceed to the next step.

Install Docker CE

Before installing Docker CE, run the following command to list the available version of Docker CE:

dnf list docker-ce

 You should get the following list:

 Available Packages
docker-ce.x86_64                                              3:19.03.11-3.el7                                               docker-ce-stable

 Now, install the latest version of Docker CE using the following command:

 dnf install docker-ce --nobest -y

 Once the installation has been completed, start the Docker CE service and enable it to start at reboot with the following command:

systemctl start docker
systemctl enable docker

You can also verify the installed version of Docker CE using the following command:

docker version 

You should get the following output: 

Client: Docker Engine - Community
 Version:          19.03.11
 API version:      1.39
 Go version:       go1.13.10
 Git commit:       42e35e61f3
 Built:            Mon Jun 1 09:13:48 2020
 OS/Arch:          linux/amd64
 Experimental:     false
 
Server: Docker Engine - Community
 Engine:
 Version:         18.09.1
 API version:     1.39 (minimum version 1.12)
 Go version:      go1.10.6
 Git commit:      4c52b90
 Built:           Wed Jan 9 19:06:30 2019
 OS/Arch:         linux/amd64
 Experimental:    false

Verify Docker

Next, you will need to run an application called hello-world to ensure our installation is working as expected.

You can test it with the following command:

docker run hello-world

If everything is working fine you should get the following output:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latest
 
Hello from Docker!

This message shows that your installation appears to be working correctly.

  1. To generate this message, Docker took the following steps:
  2.  The Docker client contacted the Docker daemon.
  3.  The Docker daemon pulled the "hello-world" image from the Docker Hub.
  4.    (amd64)
  5.  The Docker daemon created a new container from that image which runs the
  6.    executable that produces the output you are currently reading.
  7.  The Docker daemon streamed that output to the Docker client, which sent it
  8.    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/

Allow Non-root Access

By default, only root user and users with sudo privileges can run Docker containers. If you want to allow non-root user to run Docker commands, you will need to add your user to the Docker group.

You can add the user to the Docker group with the following command:

usermod -aG docker username

Now you can run a Docker with a non-root user.

Install Docker Compose

Docker Compose is a tool for running multi-container applications. It allows you to link multiple containers using a single command. If you want to launch multiple containers and these containers depend on each other then Docker Compose is very useful.

If you want to install the latest available docker-compose version, you will need to download it from the Git repository.

First, download the latest version of Docker Compose binary to the /usr/local/bin/ directory with the following command:

wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.26.0/docker-compose-Linux-x86_64

 Next, set the executable permission to docker-compose binary using the following command:

 chmod +x /usr/local/bin/docker-compose

 Next, verify the Docker Compose version using the following command:

 docker-compose --version

You should get the following output:

docker-compose version 1.26.0, build d4451659

 Conclusion

In the above guide, we learned how to install Docker CE and Docker Compose on CentOS 8.

I hope this will help you to setup Docker and Docker Compose on CentOS 8. You can now explore the Docker and start deploying your first application in a containerized environment.

Related Posts

1
2
3
4
5