Sunday, July 6, 2025
Linux Tutorial

How to Install Docker on CentOS / Rocky Linux

Docker is a popular platform for developing, shipping, and running applications in containers. Below are the steps to install Docker on CentOS / Rocky Linux.

Prerequisites

  1. A CentOS 8 system with root or sudo privileges.
  2. A stable internet connection.
  3. Terminal access.

Step 1: Update the System

Before installing Docker, ensure your system is up to date.

sudo dnf update -y

Step 2: Add the Docker Repository

Docker is not available in the default CentOS 8 repositories, so you need to add the official Docker repository.

  1. Install the dnf-plugins-core package to manage repositories:
    sudo dnf install -y dnf-plugins-core
  2. Add the Docker repository:
    sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

Step 3: Install Docker

  1. Install Docker Engine (Community Edition) and its dependencies:
    sudo dnf install docker-ce docker-ce-cli containerd.io -y
  2. Verify the installation by checking the Docker version:
    docker --version

    You should see output like: Docker version 20.10.x, build xxxxxxx.

Step 4: Start and Enable Docker

  1. Start the Docker service:
    sudo systemctl start docker
  2. Enable Docker to start on boot:
    sudo systemctl enable docker
  3. Check the status of the Docker service:
    sudo systemctl status docker

    You should see active (running) in the output.

Step 5: Verify Docker Installation

  1. Run a test container to ensure Docker is working:
    sudo docker run hello-world

    If Docker is installed correctly, you’ll see a message like:

    Hello from Docker!
    This message shows that your installation appears to be working correctly.

Manage Docker as a Non-Root User (Optional)

By default, Docker requires root privileges. To run Docker commands without sudo, add your user to the docker group:

  1. Add your user to the docker group:
    sudo usermod -aG docker $USER
  2. Log out and log back in for the changes to take effect.
  3. Verify that you can run Docker commands without sudo:
    docker run hello-world

Uninstall Docker (Optional)

If you ever need to uninstall Docker, use the following commands:

  1. Remove Docker packages:
    sudo dnf remove docker-ce docker-ce-cli containerd.io
  2. Delete Docker images, containers, and volumes:
    sudo rm -rf /var/lib/docker

You’ve successfully installed Docker on CentOS 8! You can now start using Docker to deploy and manage containers. For more advanced configurations, refer to the official Docker documentation.

A big thank you for exploring TechsBucket! Your visit means a lot to us, and we’re grateful for your time on our platform. If you have any feedback or suggestions, we’d love to hear them.

Leave a Response