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.
Prerequisites
- Rocky Linux 8 or later installed.
- Administrative access to the system.
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.
2. Update the repositories to ensure you get the latest Docker packages.
sudo dnf update
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.
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.
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)
.
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
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.
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
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.
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.