CentOSRHEL Based

How To Install Docker Compose on CentOS Stream 10

Install Docker Compose on CentOS Stream 10

Docker Compose provides an efficient way to define and run multi-container Docker applications. By grouping multiple services into a single configuration file, you can streamline your workflow and save time. CentOS Stream 10, a rolling-release Linux distribution, contains the newest updates that will become part of future CentOS releases. Combining the power of Docker Compose with CentOS Stream 10’s up-to-date environment allows for a stable, scalable, and forward-looking infrastructure. This tutorial covers each step in detail, ensuring you can install and configure Docker Compose without complications.

Introduction

Containers have revolutionized software development and deployment by enabling lightweight virtualization with minimal overhead. When you work with multiple containers, managing them individually can become cumbersome. Docker Compose solves this problem by allowing you to define all your container services in a single YAML file. This means you can spin up, spin down, and modify all related services simultaneously with just a couple of commands. Whether you’re a developer, system administrator, or hobbyist, using Docker Compose on CentOS Stream 10 can streamline your workflows, minimize manual effort, and reduce configuration errors.

CentOS Stream 10 serves as a preview of upcoming enterprise-focused features. It’s often chosen for its stability, long-term support, and robust environment. By learning how to install Docker Compose on this cutting-edge platform, you stay ahead of the curve and reduce compatibility issues over time. Furthermore, the integrated approach helps you test, iterate, and scale in a controlled environment. This guide breaks down the installation into logical steps, from preparing your system to launching your first multi-service project. Follow these instructions to harness Docker Compose effectively, build upon your knowledge, and ensure a seamless development or production experience.

Prerequisites

System Requirements

Before installing Docker Compose on CentOS Stream 10, confirm your server or local machine meets several basic requirements. At a minimum, you should have at least 2 GB of RAM and an adequate CPU to handle virtualization tasks comfortably. Keep sufficient disk space available for both the Docker Engine and your containers, especially if you plan to run multiple services.

CentOS Stream 10 must be correctly installed and fully updated. Ensure your package manager is functional and your system clocks are synchronized. Operating an up-to-date system is crucial for security and stability, especially when working with containerized environments.

Root or Sudo Privileges

You will need superuser privileges to install Docker and Docker Compose successfully. If you’re not operating as root, prepend sudo to administrative commands to grant the necessary permissions.

Internet Connection

An active internet connection is essential to pull packages from the official repositories and fetch the Docker Compose binary if you opt for manual installation. A stable network also simplifies pulling various Docker images.

Remove Existing Installations

In some cases, older versions of Docker or conflicting packages may disrupt the installation process. To ensure a smooth setup, remove any existing Docker-related applications first. For instance, run:

sudo yum remove docker docker-common docker-selinux docker-engine

This command purges conflicting Docker packages. Afterwards, clean your package manager’s cache and verify no leftover configurations remain. With these prerequisites handled, you’re ready to proceed to the main installation steps.

Installing Docker Engine

Set Up Docker Repository

Docker’s official repository contains the latest stable releases of Docker Engine. Adding it to your system repositories ensures you’ll receive timely updates, patches, and new features. Start by updating your system:

sudo dnf update -y

Next, install the required dependencies that enable secure HTTPS connections and repository management:

sudo dnf install -y dnf-plugins-core

Now, add the Docker Engine repository:

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

Once this is complete, your system recognizes Docker’s repository as an official source for installing the Docker Engine and related packages.

Install Docker Engine

With the repository in place, you’re ready to install Docker Engine. Run:

sudo dnf install docker-ce docker-ce-cli containerd.io

This command includes the core Docker packages needed to run and manage containers on your CentOS Stream 10 environment. Once installed, enable Docker to start on boot:

sudo systemctl enable docker
sudo systemctl start docker

Confirm Docker is functioning correctly:

sudo docker run hello-world

If you see a message that Docker installed successfully, everything is working as intended. This step verifies the server or machine can pull images from Docker Hub and launch them in a container.

Installing Docker Compose

Installing Docker Compose can be done in different ways, each offering its own advantages. Below are two primary methods: using the package manager (which is more straightforward if a Docker Compose plugin exists) or performing a manual binary installation (offers more direct control).

Method 1: Using Package Manager

In recent updates, Docker has transitioned to a plugin-based approach for Docker Compose. Under this system, Docker Compose is installed as a subcommand (docker compose) rather than a separate binary (docker-compose).

  1. Begin by updating the repository list again, as changes might have occurred since you installed Docker Engine:
    sudo dnf update -y
    
  2. Next, install Docker Compose as a plugin:
    sudo dnf install docker-compose-plugin
    
  3. Verify the installation:
    docker compose version
    

    If you see a version number, that means Docker Compose is successfully installed as a plugin.

  4. Optional: Allow your non-root user to run Docker commands without prefixing sudo. Simply add your username to the docker group:
    sudo usermod -aG docker <your_username>
    

    Log out and log back in for these changes to take effect.

Using Docker Compose as a plugin ensures compatibility with the latest Docker Engine distributions. This is often the most recommended approach for CentOS Stream 10 if you prefer staying on the official and supported path.

Method 2: Manual Installation of Docker Compose Binary

If the plugin method isn’t suitable for your environment, or you need a specific version of Docker Compose, you can install it manually:

  1. Identify the latest release from the official GitHub repository:
    curl -s https://api.github.com/repos/docker/compose/releases/latest \
    | grep browser_download_url \
    | grep docker-compose-$(uname -s)-$(uname -m) \
    | cut -d '"' -f 4
    

    This one-liner fetches the latest Docker Compose binary URL for your OS and architecture.

  2. Download the binary:
    sudo curl -L <paste_download_link_here> -o /usr/local/bin/docker-compose
    
  3. Set executable permissions:
    sudo chmod +x /usr/local/bin/docker-compose
    
  4. Create a symbolic link for easier access:
    sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
    
  5. Verify the installation:
    docker-compose --version
    

    A displayed version number indicates a successful install.

This method is particularly handy if you need an older stable version or a cutting-edge release not yet available in the official repositories. It offers precise control over your Docker Compose installation.

Configuration and Setup

Post-Installation Steps

After installing Docker and Docker Compose, you can enhance your setup to maximize convenience and security. First, consider adding your user to the docker group, as noted earlier, so you’re not forced to run Docker commands with superuser privileges. Additionally, ensure Docker starts automatically upon system boot:

sudo systemctl enable docker

This saves you from manually starting Docker after each reboot. Next, configure Docker’s daemon options by editing the /etc/docker/daemon.json file. You might add logging drivers, registry mirrors, or customize your storage driver, depending on the needs of your environment.

Basic Docker Compose Commands

When using Docker Compose as a plugin, commands follow the docker compose format. If you opted for the standalone binary, you’ll use docker-compose.

  • docker compose up or docker-compose up – Launch containers defined in your YAML file.
  • docker compose down or docker-compose down – Stop and remove containers, networks, and volumes that were created by up.
  • docker compose ps or docker-compose ps – View the status of running services in your multi-container application.
  • docker compose logs or docker-compose logs – Tail logs for all or selected services.

If you installed Docker Compose with the plugin approach, remember that certain advanced features may require you to confirm your Compose version. Keep your plugin updated to benefit from the latest improvements.

Creating Your First Docker Compose Project

Project Structure

Docker Compose revolves around a YAML file, often named docker-compose.yml, which defines configurations for each containerized service. In this example, create a simple Node.js application paired with a MongoDB database to illustrate multiple services running in unison. Begin by setting up a structured directory to keep everything organized:

mkdir ~/my-compose-project
cd ~/my-compose-project

Inside this directory, generate your docker-compose.yml file:

nano docker-compose.yml

Insert the following sample content:

version: "3.9"
services:
  app:
    image: node:16-alpine
    container_name: my_node_app
    working_dir: /app
    volumes:
      - .:/app
    command: ["node", "index.js"]
    ports:
      - "3000:3000"
    depends_on:
      - db

  db:
    image: mongo:5.0
    container_name: my_mongo_db
    restart: always
    ports:
      - "27017:27017"

This configuration defines two services: a Node.js application and a MongoDB database. The Node.js container mounts the current directory so your code updates reflect automatically. The depends_on property ensures the database container starts before the app container begins.

Run the following command to start your containers:

docker compose up -d

Here, the -d flag runs the containers in the background. Verify they’re up and running:

docker compose ps

Troubleshooting Common Issues

Problems may arise while installing Docker Compose or deploying multi-container applications. Below are some common scenarios and how to address them:

  • Permission Denied Errors: If you encounter permission issues running docker or docker compose, verify your user is in the docker group. Log out and log back in to refresh group memberships.
  • Network Connectivity Issues: Docker relies on network interfaces for container communication. Inspect your firewall settings and confirm that port mappings (e.g., -p 3000:3000) are correctly configured.
  • Version Compatibility Problems: If you’re mixing different versions of Docker Engine and Docker Compose (especially one installed from the binary and the other from the package manager), verify each version supports the other. Consistency helps avoid unexpected conflicts.

Most installation or functionality issues can be resolved by reinstalling the problematic package or searching through Docker’s extensive documentation. Keeping logs in mind is also crucial for deeper diagnostic insights.

Congratulations! You have successfully installed Docker Compose. Thanks for using this tutorial for installing Docker Compose on your CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Docker website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button