Live demo of agent247 on Digio's docs — click the orange button at the bottom right to start.

Installing Docker on Linux

This guide provides step-by-step instructions to install Docker on a Linux system. The instructions apply to Debian-based distributions (Ubuntu) and Red Hat-based distributions (CentOS, RHEL, Fedora).

Prerequisites

  • A 64-bit Linux system
  • Root or sudo privileges
  • Internet connection

Install Docker on Debian-based Distributions (Ubuntu, Debian)

  • Step 1: Update System Packages
    sudo apt update && sudo apt upgrade -y
    
  • Step 2: Install Required Dependencies
    sudo apt install -y ca-certificates curl gnupg lsb-release
    
  • Step 3: Add Docker’s Official GPG Key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  • Step 4: Set Up the Docker Repository
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  • Step 5: Install Docker Engine
    sudo apt update
    sudo apt install -y docker-ce docker-ce-cli containerd.io
    
  • Step 6: Start and Enable Docker
    sudo systemctl start docker
    sudo systemctl enable docker
    
  • Step 7: Verify Installation
    docker --version
    

Install Docker on Red Hat-based Distributions (CentOS, RHEL, Fedora)

  • Step 1: Update System Packages
    sudo yum update -y
    
  • Step 2: Install Required Dependencies
    sudo yum install -y yum-utils
    
  • Step 3: Add Docker Repository
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  • Step 4: Install Docker Engine
    sudo yum install -y docker-ce docker-ce-cli containerd.io
    
  • Step 5: Start and Enable Docker
    sudo systemctl start docker
    sudo systemctl enable docker
    
  • Step 6: Verify Installation
    docker --version
    

Post-Installation Steps

  • Run Docker as a Non-root User
  • sudo usermod -aG docker $USER
  • newgrp docker
  • Verify Docker Works Without Sudo
  • docker run hello-world

Uninstall Docker

  • Debian-based Systems
    sudo apt remove -y docker-ce docker-ce-cli containerd.io
    sudo rm -rf /var/lib/docker
    
  • Red Hat-based Systems
    sudo yum remove -y docker-ce docker-ce-cli containerd.io
    sudo rm -rf /var/lib/docker
    

Additional Resources

You have successfully installed Docker on your Linux system!

Was this page helpful?