How To Install Docker on Rocky Linux 8 / CentOS 8 / RHEL 8 / AlmaLinux

0
Install Docker on Rocky Linux 8
Install Docker on Rocky Linux 8

Docker is a tool that allows you to easily build, test and deploy applications smoothly and quickly using containers. It has gained widespread popularity in recent times due to the portability to run applications anywhere irrespective of the host operating system.

Docker provides a more efficient and lightweight environment to deploy the application. Docker uses Kernel’s features such as cgroups and namespace to run a container on a single os instance.

In this post, you will learn how to install Docker on Rocky Linux 8 / CentOS 8 / RHEL 8.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Docker is now available in two editions,

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

Here, we will install Docker Comunity Edition (CE).

Prerequisites

Uninstall Older Version

Uninstall older versions of Dockers, named docker or docker-engine along with associated dependencies.

dnf remove -y docker-common docker container-selinux docker-selinux docker-engine

Do not worry about the contents inside /var/lib/docker/, all will be preserved.

Install Dependent Packages

Then, install the required packages.

dnf install -y lvm2 device-mapper device-mapper-persistent-data device-mapper-event device-mapper-libs device-mapper-event-libs

Add Docker Repository

Let’s add the Docker community edition repository for the Docker installation.

dnf install -y dnf-utils

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

Install Docker on Rocky Linux 8 / CentOS 8 / RHEL 8

Install Docker packages using the below command.

dnf install -y docker-ce docker-ce-cli containerd.io
You can also install a particular version of Docker CE by appending version like docker-ce-[version]
E.g. yum install docker-ce-19.03.5-3.el7
You can list the available Docker versions with yum list docker-ce –showduplicates | sort -r

Now you have Docker installed onto your machine, start the Docker service in case if it is not started automatically after the installation

systemctl start docker

systemctl enable docker

Check the Docker service.

systemctl status docker
Docker Service Status
Docker Service Status

Verify Docker Installation

Once you start the Docker service, you can run a simple “Hello World” container to verify the installation.

docker run -it rockylinux/rockylinux echo Hello-World

When you run the docker run command, the Docker creates and starts the container with the base image of Rocky Linux.

Since we are running centos container for the first time, the output will look like below.

Unable to find image 'rockylinux/rockylinux:latest' locally
latest: Pulling from rockylinux/rockylinux
1b474f8e669e: Pull complete 
Digest: sha256:8122f31fbdd5c1368c6b7d5b9ae99fec2eb5966a5c967339d71e95c4a3ab7846
Status: Downloaded newer image for rockylinux/rockylinux:latest
Hello-World

At first, the Docker looks for Rocky Linux image locally, and if it is not found, it starts downloading the Rocky Linux image from the Docker registry (one time). Otherwise, it uses the already downloaded Rocky image.

Once the image has been downloaded (in our case), it will start the container and echo the command Hello-World in the console which you can see at the end of the output.

Allow Non-root access

By default, only users with root or sudo (root) privilege can run Docker containers. To allow non-root users to run Docker containers, you can follow the below steps.

Create a group called docker if it does not exist, run the following commands with root privileges.

groupadd docker

Add a user that is to be a part of the docker group. Replace raj with your username.

useradd raj

Add a user to the docker group.

usermod -aG docker raj

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

Interested Topics

Docker Basic Topics

1: Top Important Docker Commands – Working with Docker Containers

2: Working with Docker Images – Building Docker Images

3: How to Build Docker Images with DockerFile

Docker Advanced Topics

1: How to Setup Docker Private Registry on CentOS 7

2: How to Install and Configure Docker Swarm on CentOS 7

Conclusion

That’s All. I hope you have successfully installed Docker on Rocky Linux 8 / CentOS 8 / AlmaLinux. Please share your feedback in the comments section.

You might also like