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.