Install Docker & Compose on Rocky Linux 9

Docker Engine when used with Docker Compose can be very powerful tools for developers and Engineers working on containerized applications. While Docker Engine does the hard work of running containers, Compose simplifies the process of launching and managing multi-container applications. Docker Compose eliminates manual management of individual containers. Instead you can start, stop, and rebuild all containerized application using just a single command.

In this tutorial our attention is to help you install Docker Engine and Docker Compose on Rocky Linux 9 machine. The process should also work for similar distributions such as AlmaLinux and CentOS Stream 9.

1 – Minimum Requirements

Docker doesn’t have any strict set of minimum hardware requirements for running the service, but the hardware resources amount will heavily depend on factors such as;

  • The number of containers you intend to run
  • Storage requirements especially for persistent data
  • Each containerized application hardware requirements – such as CPU, RAM, Storage, and Network.
  • Environment – Dev environment will not have prioritized resources allocation when compared with production environment.

2 – Install Docker Engine and Compose

In this section we describe how you can install Docker Engine on Rocky Linux 9 machine. Then open source version of Docker is known as Docker CE. This is what we will install.

Add the RPM repository which contains the latest binary builds of Docker.

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

Next we install Docker Engine, containerd and Compose plugin.

sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Start and enable docker service.

 sudo systemctl enable --now docker.service

Check version to confirm of Docker Engine and Compose.

$ docker --version
Docker version 26.1.4, build 5650f9b

$ docker compose version
Docker Compose version v2.27.1

3 – Using Docker and Compose

We can run simple docker container – hello-world

$ docker run --rm hello-world sh
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

Refer to Docker CLI reference documentation for docker command usage options.

Using Docker compose

For Docker Compose, we will use Apache and PHP application.

mkdir -p apache-php/app && cd apache-php

Create Dockerfile

$ vim app/Dockerfile
FROM --platform=$BUILDPLATFORM php:8.2.10-apache as builder

CMD ["apache2-foreground"]

FROM builder as dev-envs

RUN <<EOF
apt-get update
apt-get install -y --no-install-recommends git
EOF

RUN <<EOF
useradd -s /bin/bash -m vscode
groupadd docker
usermod -aG docker vscode
EOF
# install Docker tools (cli, buildx, compose)
COPY --from=gloursdocker/docker / /

CMD ["apache2-foreground"]

Let’s add PHP application that will just print Hello World message.

$ vim app/index.php
<?php 
    echo '<h1>Hello World!</h1>'; 
?> 

Create Docker Compose file used to run the application.

$ vim docker-compose.yaml
services:
  web:
    build: app
    ports: 
      - '80:80'
    volumes:
      - ./app:/var/www/html/

Deploy the application using Compose.

$ docker compose up -d
[+] Running 2/2
 ✔ Network apache-php_default  Created                                                                                                                                                           0.1s
 ✔ Container apache-php-web-1  Started

List running container by running compose ps

$ docker compose ps
NAME               IMAGE            COMMAND                  SERVICE   CREATED          STATUS          PORTS
apache-php-web-1   apache-php-web   "docker-php-entrypoi…"   web       22 seconds ago   Up 20 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp

We can test it works by sending curl request to the home page.

$ curl 127.0.0.1:80
<h1>Hello World!</h1>

Hurrah! our Docker and Compose setup is working well. You can now use the environment for your specific personal in building and running containerized applications.

To destroy the environment just run.

$ docker compose down
[+] Running 2/1
 ✔ Container apache-php-web-1  Removed                                                                                                                                                           1.2s
 ✔ Network apache-php_default  Removed

Thanks for using our article to install Docker and Compose on Rocky Linux 9. Contact CloudSpinx for any Docker and Compose installations and configurations.

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

The web browser is the key arsenal that we use to browse the internet. If you want to access information […]

In this guide,we will look at how you can install Java 11 on Oracle Linux 8. Java is a widely […]

The adoption of Containers and microservice architectures has been amazing and speedy in the past few years. Docker is widely […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.