Share on Social Media

Learn how to install Docker Compose on CentOS 8 with this easy-to-follow guide. Get step-by-step instructions for setting up Docker Compose to manage multi-container Docker applications efficiently. #centlinux #linux #docker

What is Docker?

Docker is a set of Platform as a Service (PaaS) products that uses operating system level virtualizations to deliver software in the form of containers. Docker CE (Community Edition) is the strip down version of Docker EE (Enterprise Edition). Community Edition is free and open source and distributed under Apache License 2.0.

In Red Hat Enterprise Linux (RHEL) 8 / CentOS 8, Support of Docker has been removed by the vendor. Whereas a new containerization platform libpod (Podman’s Container Management Library) has been introduced as an alternative of Docker.

However, we can still install Docker and it’s dependencies on CentOS 8 / RHEL 8 from third party yum repositories.

In this article, we are installing Docker CE and docker-compose on CentOS 8.

Recommended Training for You: Docker for absolute beginners

5607844 2ee7show?id=oLRJ54lcVEg&offerid=1606991.5607844&bids=1606991

Docker vs Docker Compose

When comparing Docker and Docker Compose, it’s essential to understand that they serve different but complementary purposes in the containerization ecosystem. Here’s a breakdown of the key differences and use cases for each:

Docker

Overview:

  • Containerization Platform: Docker is a platform that enables developers to create, deploy, and run applications in containers.
  • Components: Includes Docker Engine, Docker CLI, Docker Hub, and Docker Desktop.

Key Features:

  • Containerization: Allows packaging applications and their dependencies into a standardized unit for software development.
  • Isolation: Provides isolated environments to run applications, ensuring consistency across different environments.
  • Images: Uses Docker images as blueprints for containers, ensuring that applications run the same way regardless of where they are deployed.
  • Docker Hub: Centralized repository for finding and sharing container images.

Use Cases:

  • Running single-container applications.
  • Development environments to ensure consistency across different stages (development, testing, production).
  • Rapidly deploying and scaling applications.

Docker Compose

Overview:

  • Tool for Multi-Container Applications: Docker Compose is a tool for defining and running multi-container Docker applications.
  • Configuration File: Uses a YAML file (docker-compose.yml) to configure the application’s services.

Key Features:

  • Multi-Container Setup: Easily defines and manages applications that require multiple interconnected containers.
  • Service Definitions: Allows defining services, networks, and volumes in a single configuration file.
  • Orchestration: Simplifies the orchestration of complex applications by allowing them to be started, stopped, and managed with simple commands.
  • Environment Management: Can define environment variables and configurations for different environments (development, testing, production).

Use Cases:

  • Applications that consist of multiple services (e.g., web server, database, cache).
  • Simplifying the development, testing, and deployment of multi-container applications.
  • Automating the configuration and setup of development environments.

Summary

Docker:

  • Best for containerizing single applications and ensuring they run consistently across different environments.
  • Provides the foundational platform for building, shipping, and running containers.

Docker Compose:

  • Best for defining and running multi-container applications.
  • Simplifies the management and orchestration of applications that involve multiple, interconnected services.

Linux Server Specification

We have configured a CentOS 8 minimal installed virtual machine with following specification.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS Linux 8.0
  • Hostname – docker-01.recipes.com
  • IP Address – 192.168.116.206 /24

Install Docker CE Yum Repository

Connect with docker-01.recipes.com using ssh as root user.

Docker CE is available to download from Docker’s official website. However, we can also install it from Docker CE yum repository.

Add Docker CE yum repository using dnf command.

# dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

Build cache for Docker yum repository.

# dnf makecache
CentOS-8 - AppStream                            7.0 kB/s | 4.3 kB     00:00
CentOS-8 - Base                                 2.2 kB/s | 3.9 kB     00:01
CentOS-8 - Extras                               1.7 kB/s | 1.5 kB     00:00
Docker CE Stable - x86_64                       6.5 kB/s |  21 kB     00:03
Metadata cache created.

Install Docker CE on CentOS 8

After addition of Docker CE yum repository, we can now easily install Docker CE on CentOS 8 by using a dnf command.

Docker CE requires containerd.io-1.2.2-3 (or later) package, which is blocked in CentOS 8. Therefore, we have to use an earlier version of containerd.io package.

Install docker-ce with an earlier version of containerd.io using following command.

# dnf -y install --nobest docker-ce

Enable and start Docker service.

# systemctl enable --now docker.service
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service â /usr/lib/systemd/system/docker.service.

Check status of Docker service.

# systemctl status docker.service
â docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor pres>
   Active: active (running) since Wed 2019-12-25 22:56:45 PKT; 30s ago
     Docs: https://docs.docker.com
 Main PID: 3139 (dockerd)
    Tasks: 17
   Memory: 66.9M
   CGroup: /system.slice/docker.service
           ââ3139 /usr/bin/dockerd -H fd://
           ââ3148 containerd --config /var/run/docker/containerd/containerd.tom>

Dec 25 22:56:45 docker-01.recipes.com dockerd[3139]: time="2019-12-25T22:56:45.>
Dec 25 22:56:45 docker-01.recipes.com systemd[1]: Started Docker Application Co>

Check Docker version.

# docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:25:41 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Docker CE has been installed on CentOS 8.

Create a Docker Container

Let’s put Docker into action by creating a simple container.

For this purpose, we are using official image of Alpine Linux from Docker Hub.

# docker search alpine --filter is-official=true
NAME                DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
alpine              A minimal Docker image based on Alpine Linux⦠  5945                [OK]

Pull Alpine Linux image from Docker Hub.

# docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
e6b0cf9c0882: Pull complete
Digest: sha256:2171658620155679240babee0a7714f6509fae66898db422ad803b951257db78
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

List locally available docker images.

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              cc0abc535e36        23 hours ago        5.59MB

Create and run a container using Alpine Linux image.

# docker run -it --rm alpine /bin/sh
/ # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.11.2
PRETTY_NAME="Alpine Linux v3.11"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://bugs.alpinelinux.org/"
/ # uname -a
Linux c0089c037e24 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 Linux
/ # exit

Install Docker Compose on CentOS 8

Additionally, we are installing docker-compose on our CentOS 8 server, so we can create and run multiple containers as a single service.

Download docker-compose package from GitHub.

# curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   617    0   617    0     0    546      0 --:--:--  0:00:01 --:--:--   546
100 16.2M  100 16.2M    0     0   184k      0  0:01:29  0:01:29 --:--:--  276k

Grant execute permissions to docker-compose command.

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

Check docker-compose version.

# docker-compose version
docker-compose version 1.25.1-rc1, build d92e9bee
docker-py version: 4.1.0
CPython version: 3.7.4
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

We have successfully install Docker-Compose on CentOS 8.

We have only explored the installation of Docker CE here, if you wish to learn more about containers then you should read Docker in Action (PAID LINK) by Manning Publications.

Final Thoughts

Installing Docker Compose on CentOS 8 is a straightforward process that significantly enhances your ability to manage multi-container Docker applications. By following the steps in this guide, you can quickly set up Docker Compose and start orchestrating your containers efficiently, making your development and deployment workflows smoother.

If you need further assistance or personalized support with your Docker Compose setup, don’t hesitate to reach out to me on Fiverr: DevOps Expert. I’m here to help you with all your Docker and containerization needs.

2 thoughts on “How to install Docker Compose on CentOS 8”

Leave a Reply