DEV Community

Randika Madhushan Perera
Randika Madhushan Perera

Posted on

Learning Docker - Installing

02. Installing Docker Community Edition on CentOS

Overview

In this lesson, we explore the process of installing Docker Community Edition (CE) on a CentOS server. The article provides a step-by-step guide to setting up Docker CE in a CentOS environment, demonstrating its installation and configuration for practical use.

Installing Docker CE

  • Installing Required Packages: Essential packages for Docker CE in CentOS, such as utils, device-mapper-persistent-data, and lvm2, are installed using the yum package manager.
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Enter fullscreen mode Exit fullscreen mode
  • Adding Docker Repository: The Docker CE repository is added using the yum-config-manager tool to ensure access to Docker packages.
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
Enter fullscreen mode Exit fullscreen mode
  • Docker Installation: Docker CE and its CLI (Command Line Interface) are installed with specific version numbers. Additionally, containerd.io is installed without specifying a version to get the latest one.
$ sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Enter fullscreen mode Exit fullscreen mode
  • Starting Docker Service: The Docker service is started and enabled to run at boot using systemctl commands. CentOS requires explicit configuration for services to start.
$ sudo systemctl enable --now docker.service
$ sudo systemctl status docker.service
Enter fullscreen mode Exit fullscreen mode

Configuring Docker CE

  • Verifying Installation: The installation's success is verified by running sudo docker version, confirming that both client and server details are returned.
  • User Permissions: To allow non-root users (like ec2-user) to execute Docker commands, they are added to the docker group using usermod.
$ sudo  usermod -aG docker ec2-user
Enter fullscreen mode Exit fullscreen mode
  • Re-login for Group Changes: Users must log out and log back in for group changes to take effect.
$ docker version
Enter fullscreen mode Exit fullscreen mode

Testing Docker Installation

  • Running a Test Container: To ensure the Docker installation is functional, a simple hello-world container is run. This container prints a message to the console and exits, indicating that Docker can pull images and run containers successfully.
$ docker run hello-world
Enter fullscreen mode Exit fullscreen mode

Top comments (0)