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.
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.
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
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.
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
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.
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.