Friday, December 27, 2024
Google search engine
HomeGuest BlogsHow to Install Docker on Rocky Linux

How to Install Docker on Rocky Linux

Introduction

Docker is an open-source Platform-as-a-Service (PaaS) solution for building, testing, and deploying applications using containers. The platform uses the Docker Engine client-server tool to create and manage container deployments.

This tutorial shows you how to install and perform the basic setup of Docker on Rocky Linux.

How to install Docker on Rocky Linux.How to install Docker on Rocky Linux.

Prerequisites

Installing Docker on Rocky Linux

The recommended method for installing Docker is to use the official repositories. While Rocky Linux is not officially supported yet, Docker’s CentOS repo provides packages fully compatible with this distribution.

Follow the steps below to install Docker Community Edition on Rocky Linux.

Step 1: Add Docker Repository

Rocky Linux uses DNF, a package manager designed for .rpm-based Linux distributions.

To add the Docker repository to your system:

1. Use the config-manager command below:

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

The output confirms the repo was added successfully.

Adding the Docker repository on Rocky Linux.Adding the Docker repository on Rocky Linux.

2. Update the repositories to ensure you get the latest Docker packages.

sudo dnf update
Updating repositories on Rocky Linux.Updating repositories on Rocky Linux.

Step 2: Install Docker Packages

Docker Community Edition requires the installation of three separate packages.

  • docker-ce is the main package.
  • docker-ce-cli provides the command-line interface.
  • containerd.io installs the containerd container runtime.

Follow these steps:

1. Install the packages with the following command:

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

DNF provides a summary of the packages scheduled for installation. It also lists missing dependencies if they exist.

Installing Docker packages on Rocky Linux.Installing Docker packages on Rocky Linux.

Type Y and press Enter to start the installation.

Step 3: Start Docker

After the installation finishes, finalize the Docker setup on your system by performing the following actions:

1. Enable Docker service with the systemctl command.

sudo systemctl enable docker

The command returns no output if it executes successfully. However, since the /etc/rc.d/rc.local script is not executable by default in Rocky Linux, attempting to enable Docker service may return the following message:

/etc/rc.d/rc.local is not marked executable, skipping.
Enabling Docker service on Rocky Linux.Enabling Docker service on Rocky Linux.

To fix this issue, make the script executable by typing:

sudo chmod +x /etc/rc.d/rc.local

After changing the file permissions, try enabling the Docker service again.

2. Start Docker with the command below.

sudo systemctl start docker

3. Check if Docker is running by typing:

systemctl status docker

The systemctl output shows the service as active (running).

Checking Docker service status on Rocky Linux.Checking Docker service status on Rocky Linux.

Step 4: Enable Non-Root User Access

After completing Step 3, you can use Docker by prepending each command with sudo. To eliminate the need for administrative access authorization, set up a non-root user access by following the steps below.

1. Use the usermod command to add the user to the docker system group.

sudo usermod -aG docker $USER

2. Confirm the user is a member of the docker group by typing:

id $USER
Checking to which groups the current user belongs.Checking to which groups the current user belongs.

3. Restart the system to apply the changes.

Note: Install Rocky Linux using the Custom OS feature on phoenixNAP’s Bare Metal Cloud and leverage the power of cloud-native dedicated servers for your workloads.

Test Docker Installation

The steps of this section walk you through a simple scenario of creating a Docker container using the image pulled from the Docker Hub. Follow the steps below to test your Docker installation.

1. Download an image to the system with the docker pull command. The example below downloads the BusyBox image.

docker pull busybox

Docker connects to Docker Hub and fetches the image.

Pulling a Docker image in Rocky Linux.Pulling a Docker image in Rocky Linux.

Note: If executing the command above returns the Permission Denied error, refer to How to Fix Docker Permission Denied? for the troubleshooting suggestions.

2. List the images available locally:

docker images
Listing Docker images in Rocky Linux.Listing Docker images in Rocky Linux.

3. Create and start a Docker container using the image you downloaded.

docker run -it busybox sh

If the command is successful, the BusyBox command prompt appears.

Running a Docker container in Rocky Linux.Running a Docker container in Rocky Linux.

Conclusion

This quick tutorial covered the steps necessary to start working with Docker on a Rocky Linux system. If you are a beginner in working with Docker, read about best practices in Docker container management, and refer to our Docker Commands Cheat Sheet.

Was this article helpful?
YesNo

RELATED ARTICLES

Most Popular

Recent Comments