Docker is a popular platform for building, shipping, and running applications in containers. Docker Compose is a tool for defining and running multi-container Docker applications. In this guide, we will walk you through the steps to install Docker and Docker Compose on AlmaLinux.

Prerequisites

Before you begin, make sure you have the following:

  1. A system running AlmaLinux.
  2. A user account with sudo privileges.

Step 1: Update the System (The Hard Way)

First, update the package index and upgrade the installed packages to their latest versions:

sudo dnf update

Step 2: Install Docker

To install Docker, you need to add the Docker repository to your system. Run the following commands to add the repository and install Docker:

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io

Step 3: Start and Enable Docker

After installing Docker, start the Docker service and enable it to start at boot:

sudo systemctl start docker
sudo systemctl enable docker

Step 4: Verify Docker Installation

To verify that Docker is installed correctly, run the following command:

docker --version

You should see output similar to the following:

Docker version 20.10.0, build 7287ab3

Step 5: Install Docker Compose

Docker Compose is a separate package that needs to be installed. You can download the latest version of Docker Compose using the following command:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

After downloading Docker Compose, make it executable:

sudo chmod +x /usr/local/bin/docker-compose

Step 6: Verify Docker Compose Installation

To verify that Docker Compose is installed correctly, run the following command:

docker-compose --version

You should see output similar to the following:

docker-compose version 1.29.2, build 5becea4c

Automate the Installation with a Bash Script (Easy Way)

To automate the installation process, you can use the following bash script:

#!/bin/bash

# Update the system
sudo dnf update -y

# Install Docker
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
sudo dnf install -y docker-ce docker-ce-cli containerd.io

# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Verify Docker and Docker Compose installations
docker --version
docker-compose --version

To use this script, simply copy the code above into a file, for example, install_docker.sh, and make it executable:

chmod +x install_docker.sh

Then, run the script with sudo:

sudo ./install_docker.sh

This script will update your system, install Docker and Docker Compose, and verify the installations.

Conclusion

In this guide, we have shown you how to install Docker and Docker Compose on AlmaLinux. You can now use Docker and Docker Compose to build, ship, and run applications in containers. If you have any questions or run into any issues, feel free to ask for help in the comments below.