DEV Community

Cover image for Docker Installation on Linux
Megha Sharma
Megha Sharma

Posted on

Docker Installation on Linux

Prerequisites

Before diving into the installation process, ensure that you have:

  • A Linux-based operating system (such as Ubuntu, CentOS, or Fedora).
  • Administrative privileges on the system to install packages.

Now, let’s get started with the installation.

Step 1 — Uninstall old versions:

sudo yum remove -y docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
Enter fullscreen mode Exit fullscreen mode
  • sudo: This is used to execute the following command with elevated privileges.
  • yum remove -y: This part of the command is using the yum package manager to remove specified packages.
  • remove is the subcommand indicating that you want to uninstall packages.
  • -y is an option that automatically answers “yes” to any prompts during the removal process. This can be useful when running the command in a script or when you want to avoid manual confirmation.
  • docker, docker-client, docker-client-latest, docker-common, docker-latest, docker-latest-logrotate, docker-logrotate, docker-engine: These are the names of the Docker-related packages to be removed. By listing these packages, you are instructing yum to uninstall all of them from your system.

After running this command, the specified Docker packages and their dependencies should be removed from your CentOS system. It’s a common practice to uninstall older versions before installing a newer version to ensure a clean and consistent Docker installation.

Step 2 — Add the Utilities needed for Docker:

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
Enter fullscreen mode Exit fullscreen mode
  • yum install -y: This part of the command is using the yum package manager to install software packages.
  • install is the subcommand indicating that you want to install packages.
  • -y is an option that automatically answers “yes” to any prompts during the installation process. This can be useful when running the command in a script or when you want to avoid manual confirmation.
  • yum-utils: This is the first package to be installed. It is a collection of utilities and plugins for yum that provide additional functionalities for package management.
  • device-mapper-persistent-data: This is the second package to be installed. It is related to device-mapper, which is used for managing storage devices on Linux.
  • lvm2: This is the third package to be installed. It stands for Logical Volume Manager version 2, and it is used for managing logical volumes on Linux systems.

By running this command, you are installing these three packages on your system, and the -y flag ensures that you won’t be prompted for confirmation during the installation process.

Step 3 — Set up the stable repository:

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
Enter fullscreen mode Exit fullscreen mode
  • yum-config-manager: This command is part of the yum-utils package, and it’s used to manage YUM configuration settings.
  • — add-repo: This option is used with yum-config-manager to add a new repository configuration.
  • [https://download.docker.com/linux/centos/docker-ce.repo] This is the URL of the Docker repository configuration file for CentOS. By adding this repository, you make Docker packages available for installation and updates using the yum package manager.

After running this command, you should have the Docker repository added to your YUM configuration, allowing you to install Docker packages on your CentOS system using YUM.

Step 4 — Install Docker CE

sudo yum -y install docker-c
Enter fullscreen mode Exit fullscreen mode

Step 5 — Enable and start Docker

sudo systemctl start docker && sudo systemctl enable docker
Enter fullscreen mode Exit fullscreen mode
  • systemctl start docker: This command starts the Docker service. The start subcommand is used to initiate the service immediately.
  • &&: This is a logical operator that allows you to run multiple commands sequentially. In this case, the second command (sudo systemctl enable docker) will only be executed if the first command (sudo systemctl start docker) is successful.
  • sudo systemctl enable docker: This command enables the Docker service to start automatically at boot. The enable subcommand configures the service to start on boot, ensuring that Docker is available even after a system reboot.

So, when you run this entire command, it starts the Docker service immediately and ensures that it will be started automatically on subsequent system reboots. This is a common sequence of commands when setting up Docker on a Linux system.

Step 6 — Docker version

sudo docker version
Enter fullscreen mode Exit fullscreen mode

Step 7 — Add user: megha to the docker groupCOPY

sudo usermod -aG docker megha
Enter fullscreen mode Exit fullscreen mode
  • usermod: This is a command used to modify user account properties on a Linux system.

-aG docker: These are options passed to the usermod command:

  • -a: This option stands for “append” and is used to add the user to the specified group without removing the user from other groups.
  • -G: This option specifies the groups to which the user should be added. In this case, it is the “docker” group.
  • megha: This is the username of the user that you want to modify and add to the “docker” group.

In summary, the command is adding the user “megha” to the “docker” group. Users in the “docker” group typically have permission to interact with the Docker daemon, allowing them to run Docker containers without needing to use sudo for every Docker command. After running this command, the user “megha” should have the necessary permissions to work with Docker on the system.

The output megha wheel docker from the id -nG megha command indicates that the user “megha” is a member of three groups: “megha”, “ec2-user”,and “docker”.

The “megha” group is likely a group with the same name as the user, which is a common practice on Linux systems.

The “ec2-user” group is a special administrative group on some systems, often used for granting sudo (superuser) privileges.

The “docker” group is typically associated with the Docker daemon and allows users in this group to run Docker containers without needing to use sudo for every Docker command.

Top comments (0)