How to Install Docker on CentOS and Rocky Linux

October 30, 2024

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
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to Install Docker on Raspberry Pi
December 12, 2019

If you want to install Docker on Raspberry Pi, that is on its Raspian system, you need to use the automated...
Read more
How to Install phpMyAdmin on CentOS 7
November 20, 2024

This guide is for users who have already configured a CentOS server and installed the Apache HTTP services...
Read more
How to Install MySQL 8.0 in Ubuntu 18.04
December 12, 2018

MySQL is an open-source relational database server tool for Linux operating systems. It is widely used in...
Read more
How to Manage Docker Containers? Best Practices
January 29, 2019

With Docker Container Management you can manage complex tasks with few resources. Learn the best practices of...
Read more