11.12.2024

How to Install Docker and Docker compose on CentOS 8

Docker is a container management system. The Linux distribution and the necessary applications for the software being developed are deployed inside the container. Once configured, the container can be moved to any operating system where docker is installed, and work there without any additional steps. This is the reason for the popularity of Docker among developers and DevOps.

In the Serverspace you can create a server with already installed app "Docker".

In this tutorial, we will install Docker, Docker compose, and run a test container.

Docker installation on CentOS 8

To install and always update Docker to the latest version, add the developer repository to the system.

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

Install the Docker package.

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

Start the Docker service and add it to autorun.

systemctl enable --now docker

CentOS 8 uses a firewall other than Docker. Hence, if you have firewalld enabled, you need to add a masquerade rule to it.

firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --reload

Docker compose installation

Docker is often installed along with Docker compose. It is this utility that allows you to deploy your project to another machine using one command. To download it, run the following command:

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

Make it executable.

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

Using Docker as a non-root user

To be able to use Docker as a non-root user, you must add that user to the docker group.

usermod -aG docker username

Replace the username with the desired user name. After executing this command, he will need to log out from the system and log in again.

Be careful! Users of this group can take control of the Docker host.

Docker test container running

You can verify that Docker is working properly by running a test container.

docker run hello-world

As a result of executing the command, you should see a message that everything is working well.