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 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.
sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Output akan seperti ini :
[masadmin@dev-20 ~]$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo [sudo] password for masadmin: Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo [masadmin@dev-20 ~]$
Install the Docker package.
sudo dnf install docker-ce docker-ce-cli containerd.io
Start the Docker service and add it to autorun.
sudo 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/v2.19.1/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
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.