How to Install Docker on CentOS and Rocky Linux

By
Marko Aleksic
Published:
October 30, 2024
Topics:

Introduction

Docker is a popular software package that creates and manages containers for application development. The platform creates a uniform interface so that almost any application running on it is cross-platform compatible.

In this guide, learn how to install Docker on CentOS and Rocky Linux.

Install Docker on CentOS and Rocky Linux article

Prerequisites

  • A maintained/supported version of CentOS or Rocky Linux.
  • A user account with sudo privileges.
  • Terminal access (Right-click desktop, click Open in Terminal).

Installing Docker on CentOS and Rocky Linux with Yum

Installing from Docker repositories using the yum command is the easiest and most popular method.

Step 1: Update Docker Package Database

In a terminal window, type:

sudo yum check-update

Allow the operation to finish.

Step 2: Install Dependencies

The next step is to download the dependencies required to install Docker. Type in the following command:

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

The yum-utils package adds the yum-config-manager. Docker uses a device mapper storage driver, and the device-mapper-persistent-data and lvm2 packages are required for its installation.

The command for installing Docker dependencies on CentOS 7 and Rocky Linux.

Step 3: Add Docker Repository to CentOS or Rocky Linux

To install Docker, you must add the Docker CE stable repository to your system. To do so, run the command:

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
A command for adding the Docker CE stable repository to CentOS 7 and Rocky Linux.

Step 4: Install Docker On CentOS or Rocky Linux Using Yum

With everything set, install Docker on CentOS or Rocky Linux by running:

sudo yum install docker-ce docker-ce-cli containerd.io

The system should begin the installation. Once it finishes, it will notify you the installation is complete and which version of Docker is now running on the system.

Output confirming Docker has been installed on your CentOS 7 and Rocky Linux.

Step: 5 Manage Docker Service

To start the service, enable it to run at startup. Run the following commands in the order listed below:

1. Start Docker:

sudo systemctl start docker

2. Enable Docker:

sudo systemctl enable docker

3. Check the status of the service with:

sudo systemctl status docker
Output confirming the Docker service is active and running.

Install Specific Version of Docker on CentOS or Rocky Linux

To install a specific version of Docker, start by listing the available releases. To do so, type the following in your terminal window:

yum list docker-ce --showduplicates | sort โ€“r

Install the selected Docker version with the command:

sudo yum install docker-ce-[version]

The [version] is in the middle column and is the first part of the alphanumeric code before the hyphen.

Where to find a list of all the available Docker versions.

Conclusion

This guide showed you how to set up Docker on your CentOS or Rocky Linux machine. It contained instructions on how to add the official Docker repository, install Docker, and enable the service.

For more information about Docker, read What is Docker? Objects, Tools, and Workflow Explained.

Was this article helpful?
YesNo