How to Deploy and Use the Rocky Linux Docker Image: A Step-by-Step Guide
Docker containers have become a crucial tool for developers and system administrators alike, offering a flexible, lightweight solution for deploying and managing applications across multiple environments. Rocky Linux, known for its reliability and stability, has gained popularity as a CentOS replacement and is widely supported in cloud and containerized environments. This guide will walk you through deploying and using the Rocky Linux Docker image, covering everything from setting up Docker to deploying your customized Rocky Linux image with Apache pre-installed.
Prerequisites
To follow along, you'll need:
For this tutorial, we'll work with Ubuntu Server 22.04 as the host operating system.
Installing Docker on Ubuntu Server 22.04
If Docker is not yet installed on your system, you can set it up easily on Ubuntu by running:
sudo apt-get install docker.io -y
Once installed, add your user to the Docker group to avoid using sudo with every Docker command:
sudo usermod -aG docker $USER
Log out and log back in for these changes to take effect.
Step 1: Pull the Latest Rocky Linux Image
To deploy Rocky Linux in a container, you first need to download its image. The Rocky Linux image is available on Docker Hub, and you can pull the latest version by running:
docker pull rockylinux/rockylinux
After the image download completes, you can verify that it’s available by listing all downloaded Docker images:
docker images
You should see an entry for rockylinux/rockylinux in the list, confirming that the image is ready to use.
Step 2: Deploy a Rocky Linux Container
With the Rocky Linux image downloaded, you’re ready to launch a container. Here’s how to create and start a new container from the image:
docker run -it --name rocky -d rockylinux/rockylinux
In this command:
Verify that your new Rocky Linux container is up and running by listing all active containers:
docker ps
You should see your rocky container in the output.
Step 3: Modify the Running Container
Now, let’s install the Apache web server in our running Rocky Linux container to give it some functionality. To access the container’s shell, run:
docker exec -it --user root rocky /bin/bash
This command opens an interactive shell with root privileges in the container. Once you’re at the Rocky Linux prompt inside the container, install Apache using:
dnf install httpd -y
Start the Apache server with:
Recommended by LinkedIn
httpd
You can verify that Apache is running correctly by executing a curl command within the container:
curl localhost
This should return the HTML for the Apache Welcome page, confirming that Apache is operational.
Step 4: Create a New Rocky Linux Image with Apache
Now that you have Apache installed and running in your Rocky Linux container, you might want to save this customized state as a new Docker image. This way, you can quickly deploy containers with Apache pre-installed.
Exit the container shell by typing:
exit
1.
Next, locate the container ID of the running Rocky Linux container by listing all active containers:
docker ps
2.
The container ID is a long alphanumeric string; you’ll only need the first four characters to identify it.
Create a new image based on the customized container. Replace ID with the first four characters of your container ID, and name the new image rocky-httpd:
docker commit ID rocky-httpd
3.
This docker commit command captures the current state of your container, including the Apache installation, and saves it as a new image.
Verify that the new image was created by listing all Docker images:
docker images
4.
You should now see rocky-httpd in the list, which contains the customized Rocky Linux setup with Apache.
Step 5: Stop the Original Container (Optional)
To clean up your environment, you can stop the original rocky container now that you’ve saved its state as a new image. Use the following command, substituting ID with the actual container ID of the rocky container:
docker stop ID
Step 6: Deploy a New Container from Your Custom Image
Now that you have a new Rocky Linux image with Apache installed, you can quickly deploy another container from this image without needing to install Apache again. Use the following command to launch a container named rocky-web from the rocky-httpd image:
docker run -it --name rocky-web -d rocky-httpd
Your new container will now start with Apache ready to go. This setup can save you time and resources if you plan to deploy multiple instances with similar configurations.
Wrapping Up
Congratulations! You’ve successfully:
By following these steps, you now have a reliable method for deploying Rocky Linux in a Docker environment, complete with pre-installed applications to streamline your development or deployment process. This approach is especially useful when working with multiple containers that require consistent configurations.