How to Install Docker on CentOS or RHEL Based Linux

Laptop with application loading

How to Install Docker on CentOS or RHEL Based Linux

Docker has gained immense popularity in recent years, revolutionizing software development practices through containerization. Containerization simplifies the shipping of applications along with their dependencies in a single encapsulated unit, eliminating compatibility issues across different machines. This guide presents a step-by-step tutorial on installing Docker on CentOS or any Red Hat Enterprise Linux (RHEL) based system. For those new to virtualization, we also offer guidance on how to install CentOS 8 in a VirtualBox.

Prerequisites Check

Before delving into the Docker installation process, ensure that the centos-extras repository is enabled on your system. Execute the command below, and confirm that centos-extras is listed in your repository inventory.

yum repolist -v

Preparing Your System

If you possess an older Docker version, it’s recommended to uninstall it before proceeding. However, if your system is free of any previous installations, this step can be skipped. To remove an outdated Docker version, use the following command:

sudo yum remove docker docker-client docker-client-latest docker-c

To integrate the Docker repository into your CentOS machine, you first need to install yum-utils. Afterward, proceed to add the repository.

sudo yum install -y yum-utils sudo yum-config-manager --add-repo 

Installing Docker on CentOS

With the prerequisites in place, you are now primed to configure Docker. The initial step involves updating your system’s repository.

sudo yum -y update

  • In cases where an error indicating a conflict between containerd.io and runc emerges, execute the following to resolve the issue:
sudo yum erase podman buildah
  • Subsequently, install Docker using the command:
sudo yum install docker-ce docker-ce-cli containerd.io

Should the Docker installation prove successful, there is no need to continue with this step. Proceed to the subsequent section for configuring Docker. Conversely, if you encounter a failure where docker-ce requires a version of containerd.io higher than what is available in the repository, you can address this by manually installing containerd.io.

Configuring Docker

With Docker successfully installed, a few configuration steps remain. Begin by adding your user to the docker group. To determine if your user is already part of the docker group, execute the command:

groups <username>

  • Should your user not be listed, you can include it in the docker group using:
sudo usermod -aG docker <username>
  • For example:
sudo usermod -aG docker javapointers

To verify the inclusion, rerun the group’s command and ensure your user now belongs to the docker group.

  • Subsequently, add Docker as a service that starts automatically during boot using:

sudo systemctl enable docker sudo systemctl start docker

  • To conclude the installation process, restart your virtual machine and execute the following command to verify that Docker is functioning properly:
docker run hello-world
  • Upon observing an output similar to the one shown below, you have triumphantly installed Docker on your CentOS or RHEL based system.

Hello from Docker! …

Docker Installation and Configuration Summary

Here’s a comparison table summarizing the steps involved in installing and configuring Docker on CentOS or RHEL based Linux systems:

StepDescription
Prerequisites CheckVerify the centos-extras repository is enabled.
Preparing Your SystemUninstall old Docker versions and set up the Docker repository.
Installing Docker on CentOSUpdate the repository, install Docker, and address potential containerd.io version conflicts.
Configuring DockerAdd your user to the docker group, enable Docker as a service, and test Docker with a container.

Video explanation

In order to make it even clearer to you, we want to show you a visual video.

Conclusion

Congratulations on successfully installing Docker on your CentOS or RHEL based Linux machine! This guide has provided you with comprehensive steps to seamlessly set up Docker and employ it for your containerization needs. If you encounter any challenges or have questions, please share your experiences and inquiries in the comments section below. Your feedback is invaluable in aiding fellow readers to navigate any potential roadblocks during their Docker installation journey.

FAQ

Why is the centos-extras repository important?

The centos-extras repository provides additional packages that are not included in the default CentOS repository. These packages may include updates, enhancements, and dependencies that are crucial for the proper functioning of Docker and other software.

How does Docker improve software development?

Docker streamlines software development by packaging applications and their dependencies into isolated containers. These containers can be easily replicated across different environments, ensuring consistent behavior and minimizing compatibility issues.

Can I install Docker on a virtual machine?

Yes, you can install Docker on a virtual machine. The installation process remains the same as on a physical machine. However, ensure that the virtual machine meets the system requirements for Docker to operate optimally.

What is the purpose of adding my user to the docker group?

Adding your user to the docker group grants non-root users the ability to interact with Docker without needing superuser privileges. This is essential for running Docker commands and managing containers seamlessly.

No Comments

Sorry, the comment form is closed at this time.