Complete Guide to Deploying Rocky Linux with Docker

Rocky Linux, as the optimal alternative after CentOS has ceased updates, is fully compatible with RHEL and offers 10 years of long-term support, making it the preferred choice for enterprise-level server deployments. Deploying via Docker can completely resolve traditional deployment issues such as “environment inconsistency, cumbersome migration, and chaotic version management,” making it particularly suitable for scenarios like migrating legacy CentOS systems and building enterprise-level services. Below, we will guide you through the entire process from environment preparation to deployment verification, leveraging the features of the Xuanyuan image platform.

About Rocky Linux

1. Core Values of Rocky Linux

As a community distribution initiated by the founder of CentOS, its core competitive advantages focus on three points:

  • Maximum Compatibility: Built from RHEL source code, it matches RHEL functionality 1:1 after removing branding, allowing seamless migration of applications from the original CentOS without configuration changes.
  • Long-term Stable Support: Each version provides 10 years of security updates; for example, Rocky Linux 8 is supported until 2029, and 9 until 2032, far exceeding typical release cycles.
  • Multi-architecture Adaptation: Natively supports architectures such as amd64, arm64v8, ppc64le, s390x, covering all scenarios including physical machines, cloud servers, and embedded devices.

2. Core Advantages of Deploying Rocky Linux with Docker

Compared to traditional CD installations or ISO deployments, the advantages of the Docker method align more closely with modern operational needs:

  • Environment Consistency: The image is packaged with complete dependencies, allowing it to be “ready to use” as long as Docker can run, avoiding “works locally, errors online” issues.
  • Lightweight and Efficient: Containers only occupy process-level resources, saving over 80% memory compared to virtual machines, with the Rocky Linux base image being around 200MB and startup time not exceeding 3 seconds.
  • Version Isolation: Allows running both Rocky Linux 8 and 9 containers simultaneously, deploying applications with different version dependencies without interference.
  • Rapid Migration: Cross-server migration can be completed in 3 minutes through image export/import, improving efficiency by 10 times compared to traditional “reinstalling the system + configuring the environment”.
  • Simplified Management: Docker commands can be used for starting, stopping, backing up, and updating, making it easy for beginners to get started without mastering complex Linux installation processes.

🧰 Preparation Work

Before deployment, ensure that the Docker environment is installed. Users who have not installed it can follow the steps below:

One-click Installation of Linux Docker & Docker Compose

It is recommended to use the one-click installation script provided by Xuanyuan Image, which supports mainstream distributions such as CentOS, Ubuntu, and Debian, and automatically configures image acceleration sources:

# One-click installation of Docker and Docker Compose
bash <(wget -qO- https://xuanyuan.cloud/docker.sh)

Verify Installation Results

Execute the following command; if the output shows Docker and Docker Compose version information, the installation is successful:

docker --version && docker compose --version

Example output (version numbers may vary, normal):

Docker version 27.0.3, build 7d4bcd8
Docker Compose version v2.20.2

1. View and Pull Rocky Linux Image

The Rocky Linux image has been synchronized to the Xuanyuan image platform, supporting multiple versions and minimal versions, and can be pulled according to demand:

1.1 Image Information Query

First, visit the Rocky Linux details page on the Xuanyuan image platform to view tags, update records, and other information:👉 Xuanyuan Image Rocky Linux Page[1]

Key Tip: No <span>latest</span> tag, you need to specify the major version number (8 or 9), and it is recommended to choose version 9 (the latest stable version) first; a <span>minimal</span> version (only contains basic dependencies, smaller size) is also provided.

1.2 Various Pull Methods (Choose as Needed)

Method 1: Xuanyuan Image Pull Without Login (Recommended for Beginners)

No account configuration is required; directly pull the latest stable version (taking version 9 as an example):

# Pull Rocky Linux 9 Base Version
docker pull xxx.xuanyuan.run/library/rockylinux:9

# If you need the minimal version, pull the minimal tag
docker pull xxx.xuanyuan.run/library/rockylinux:9-minimal

Method 2: Xuanyuan Image Pull with Login (Enterprise Users)

Users registered on the Xuanyuan image platform can pull via login:

# Login to Xuanyuan Image (first-time users need to enter username and password)
docker login docker.xuanyuan.run

# Pull Rocky Linux 8 version (for legacy applications)
docker pull docker.xuanyuan.run/library/rockylinux:8

Method 3: Official Docker Hub Pull (Get the Latest Image)

Due to technical limitations, Xuanyuan Image may not have synchronized the latest image; if you need the latest version, you can pull directly from the official repository:

# Official Repository Pull Rocky Linux 9
docker pull rockylinux/rockylinux:9

Method 4: Pull and Rename (Simplify Subsequent Commands)

If the pull address is too long, you can rename it to a simpler tag:

# Rename the image pulled from Xuanyuan Image to rockylinux:9
docker tag xxx.xuanyuan.run/library/rockylinux:9 rockylinux:9

# Delete the original tag (optional, to save space)
docker rmi xxx.xuanyuan.run/library/rockylinux:9

1.3 Verify Pull Results

Execute the following command; if you can see the Rocky Linux image information, the pull is successful:

docker images | grep rockylinux

Example output:

REPOSITORY          TAG           IMAGE ID       CREATED        SIZE
rockylinux          9             7f277199191f   2 weeks ago    205MB
rockylinux          9-minimal     8a3f8d44444c   2 weeks ago    110MB

2. Deploying Rocky Linux in Practice

This article provides a complete solution from “quick testing” to “enterprise-level deployment” based on different usage scenarios, all demonstrated using Rocky Linux version 9.

2.1 Quick Deployment

Suitable for temporary verification environments, learning Linux commands, etc., one-click to start an interactive container:

# Start the container and enter the command line, named rocky-test
docker run -it --name rocky-test rockylinux:9 /bin/bash

Core Parameter Explanation

  • <span>-it</span>: Runs interactively, keeping the terminal connection (allows direct command input inside the container).
  • <span>--name rocky-test</span>: Assigns a fixed name to the container for easier management later.
  • <span>/bin/bash</span>: By default, enters the Bash command line after starting.

Basic Operation Demonstration

After entering the container, you can execute the following commands to verify the environment:

# Check system version (confirm it is Rocky Linux 9)
cat /etc/rocky-release

# Install basic tools (test package manager)
dnf install -y wget vim

# Exit the container (temporary exit keeps the container: Ctrl+P+Q; completely exit stops the container: exit)

2.2 Directory Mount Deployment (Recommended for Production Scenarios)

By mounting host directories, achieve “data persistence, independent configuration management, and log separation,” avoiding data loss after container destruction.

Step 1: Create Host Mount Directories

Create data, configuration, and log directories based on actual needs (paths can be customized):

# Create three core directories at once
mkdir -p /data/rocky/{data,conf,logs}

# Authorize the directories (to avoid insufficient permissions inside the container)
chmod -R 777 /data/rocky

Step 2: Start the Container and Mount Directories

docker run -d --name rocky-prod \
  -p 2222:22 \  # Map SSH port (for remote connection to the container)
  -p 8080:80 \  # Map HTTP port (for subsequent service deployment)
  -v /data/rocky/data:/var/data \  # Data directory mount
  -v /data/rocky/conf:/etc/custom \  # Custom configuration directory mount
  -v /data/rocky/logs:/var/log/custom \  # Log directory mount
  -e TZ=Asia/Shanghai \  # Set timezone (to resolve container timezone deviation)
  rockylinux:9 \
  # Run in the background (ensure the container does not exit)
  /bin/bash -c "dnf install -y crond &amp;&& crond -n"

Directory Mapping Explanation

Host Directory Container Directory Core Purpose
<span>/data/rocky/data</span> <span>/var/data</span> Store business data (e.g., database files)
<span>/data/rocky/conf</span> <span>/etc/custom</span> Store custom configuration files
<span>/data/rocky/logs</span> <span>/var/log/custom</span> Store application logs

Enter the Running Container

If you need to operate the container after deployment, execute the following command:

# Enter the started rocky-prod container
docker exec -it rocky-prod /bin/bash

2.3 Docker Compose Deployment (Enterprise-level Batch Management)

Suitable for multi-service combination scenarios (e.g., Rocky Linux + Nginx + MySQL), managed uniformly through configuration files, supporting one-click start and stop.

Step 1: Create docker-compose.yml Configuration File

Create the configuration file in any directory (recommended to place in <span>/data/rocky-compose</span> directory):

version: '3.8'  # Adapted for new versions of Docker Compose
services:
  rocky:
    image: rockylinux:9  # Image used
    container_name: rocky-service  # Container name
    ports:
      - "2222:22"
      - "8080:80"
    volumes:
      - ./data:/var/data
      - ./conf:/etc/custom
      - ./logs:/var/log/custom
    environment:
      - TZ=Asia/Shanghai  # Timezone configuration
      - LANG=en_US.UTF-8  # Character set configuration
    restart: always  # Automatic restart on container failure (ensures high availability)
    command: /bin/bash -c "dnf install -y openssh-server &amp;&& /usr/sbin/sshd -D"  # Start SSH service

Step 2: Create Corresponding Directories and Start

# 1. Create directories corresponding to the configuration file
mkdir -p /data/rocky-compose/{data,conf,logs}
cd /data/rocky-compose

# 2. Start the service (run in the background)
docker compose up -d

# 3. Common management commands
docker compose ps  # View service status
docker compose stop  # Stop the service
docker compose down  # Stop and remove the container
docker compose logs -f  # View logs in real-time

3. Deployment Result Verification

Confirm that the Rocky Linux container is running normally through the following methods:

3.1 Basic Status Verification

# Check if the container is running (STATUS column shows Up means normal)
docker ps | grep rocky

# Check container resource usage (confirm memory and CPU usage is normal)
docker stats rocky-prod

3.2 Environment Function Verification

# 1. Enter the container
docker exec -it rocky-prod /bin/bash

# 2. Verify package manager (Rocky Linux 9 uses dnf by default)
dnf update -y  # Update system packages
dnf install -y nginx  # Install Nginx for testing

# 3. Verify mounted directory (create a file inside the container and check if it syncs to the host)
echo "test data" &gt; /var/data/test.txt
exit  # Exit the container

# 4. Check the file on the host (confirm mount is effective)
cat /data/rocky/data/test.txt

3.3 Service Access Verification

If the 80 port was mapped during deployment and Nginx was installed, you can verify through a browser or curl:

# Host access to Nginx inside the container
curl http://127.0.0.1:8080

If the Nginx welcome page content is displayed, the service deployment is successful.

4. Common Problem Troubleshooting

4.1 Prompt “No latest tag” when pulling the image

Reason: The official Rocky Linux does not provide a latest tag; you need to specify a specific version.Solution: Use <span>rockylinux:9</span> or <span>rockylinux:8</span> instead of latest, for example:

docker pull rockylinux/rockylinux:9

4.2 Minimal version cannot use dnf command

Reason: The minimal version only installs the microdnf lightweight package manager by default.Solution: Use microdnf directly or install dnf:

# Use microdnf to install software
microdnf install -y vim

# Or install the full dnf (suitable for long-term use)
microdnf install -y dnf

4.3 Incorrect timezone display inside the container (8 hours difference from local)

Solution: Add timezone environment variable at startup, or manually modify after entering the container:

# Specify timezone at startup (recommended)
docker run -d -e TZ=Asia/Shanghai --name rocky-test rockylinux:9

# Modify timezone for already started container (temporary solution)
docker exec -it rocky-test /bin/bash
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
date  # Verify timezone

4.4 Permission denied after mounting directory

Reason: Insufficient permissions on the host directory, the user inside the container has no read/write permissions.Solution: Authorize the host directory or specify the root user at startup:

# 1. Authorize the host
chmod -R 777 /data/rocky

# 2. Or specify root user at startup
docker run -d -u root --name rocky-prod -v /data/rocky:/var/data rockylinux:9

4.5 Slow speed when installing software with dnf

Solution: Replace with domestic mirror sources (using Alibaba Cloud as an example):

# Execute inside the container
echo -e "[base]\nname=Rocky Linux $releasever - Base - mirrors.aliyun.com\nbaseurl=http://mirrors.aliyun.com/rocky/$releasever/BaseOS/$basearch/os/\ngpgcheck=1\ngpgkey=http://mirrors.aliyun.com/rocky/RPM-GPG-KEY-Rocky-9" &gt; /etc/yum.repos.d/base.repo
dnf clean all &amp;&& dnf makecache

Conclusion

By now, you have mastered the complete process of deploying Rocky Linux with Docker—from various methods of pulling images to deployment practices suitable for different scenarios, and solutions to common problems, each step aligns with actual operational needs.

For beginners, it is recommended to start with “quick deployment” to familiarize yourself with the Rocky Linux environment, and then try the “directory mount” solution to understand the importance of persistence; enterprise users are recommended to directly use “Docker Compose deployment,” combined with image acceleration and domestic source optimization, to support production-level service operations.

Reference Links

<span>[1]</span> Xuanyuan Image Rocky Linux Page: https://xuanyuan.cloud/r/rockylinux/rockylinux

Leave a Comment