How To Install Docker On Linux

How To Install Docker On Linux

Reading time1 min
#Docker#Linux#DevOps#Containerization#LinuxDistros#DockerInstallation

Step-by-Step Guide to Seamlessly Install Docker on Any Linux Distribution

Mastering Docker installation on Linux is foundational for developers and sysadmins aiming for efficient containerized environments. Docker facilitates consistent app deployment and scalability across diverse systems, but the installation process can vary depending on your Linux distribution. Forget the one-size-fits-all tutorials. This guide breaks down the nuances of installing Docker on multiple Linux distros, highlighting important distro-specific tweaks that ensure a smooth setup and optimal performance from the start.


Why Install Docker on Linux?

Docker is the leading containerization platform that allows you to package applications and their dependencies into lightweight containers. Installing Docker on Linux is a common starting point for:

  • Developing portable, scalable applications
  • Managing microservices architectures
  • Testing software in isolated environments
  • Automating deployment pipelines

Since Linux powers most cloud servers and development environments, installing Docker directly on your Linux machine ensures full control and flexibility.


General Prerequisites

Before diving into installation, ensure your system meets the following:

  • A 64-bit Linux OS (Ubuntu, Debian, Fedora, CentOS, Arch Linux, etc.)
  • Kernel version 3.10 or higher (run uname -r to check)
  • Sudo or root privileges
  • Network connectivity for downloading Docker packages

Step 1: Uninstall Old Versions (If Any)

If you have any older Docker versions (such as docker, docker-engine, or docker.io) installed, remove them first to avoid conflicts:

sudo apt-get remove docker docker-engine docker.io containerd runc

This is an Ubuntu/Debian command; adapt accordingly for other distros (e.g., use yum remove on CentOS).


Step 2: Install Docker on Popular Linux Distros

Although Docker provides official installation instructions, the commands can vary slightly for each distro. Here’s a breakdown:

A. Ubuntu

  1. Update your package index:

    sudo apt-get update
    
  2. Install packages to allow apt to use a repository over HTTPS:

    sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
    
  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
    
  4. Set up the stable 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
    
  5. Install Docker Engine:

    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io
    
  6. Verify Docker installation:

    sudo docker run hello-world
    

B. Debian

Debian’s steps are similar to Ubuntu, but use Debian’s package tools and codename:

  1. Prerequisites:

    sudo apt-get update
    sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
    
  2. Add Docker’s GPG key:

    curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  3. Add the Docker repo (replace buster or bullseye with your Debian version):

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    
  4. Install Docker:

    sudo apt-get update
    sudo apt-get install docker-ce docker-ce-cli containerd.io
    
  5. Test:

    sudo docker run hello-world
    

C. Fedora

Fedora uses dnf and has its own repo setup:

  1. Remove old Docker versions:

    sudo dnf remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
    
  2. Set up the Docker repository:

    sudo dnf -y install dnf-plugins-core
    sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
    
  3. Install Docker Engine:

    sudo dnf install docker-ce docker-ce-cli containerd.io
    
  4. Start Docker and enable on boot:

    sudo systemctl start docker
    sudo systemctl enable docker
    
  5. Verify installation:

    sudo docker run hello-world
    

D. CentOS 7/8

CentOS uses yum or dnf (CentOS 8):

  1. Remove old Docker versions:

    sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
    
  2. Set up the repo:

    sudo yum install -y yum-utils
    sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    
  3. Install Docker:

    sudo yum install docker-ce docker-ce-cli containerd.io
    
  4. Start and enable Docker:

    sudo systemctl start docker
    sudo systemctl enable docker
    
  5. Test Docker:

    sudo docker run hello-world
    

E. Arch Linux

On Arch, Docker is available in the official repos:

sudo pacman -Syu docker
sudo systemctl start docker.service
sudo systemctl enable docker.service

Verify with:

sudo docker run hello-world

Step 3: Post-Installation Steps (Optional but Recommended)

Add Your User to docker Group to Avoid sudo

By default, Docker commands require root. For convenience:

sudo usermod -aG docker $USER

Log out and back in for the group change to take effect, then run:

docker run hello-world

without sudo.


Enable Docker to Start on Boot

Make sure Docker service launches on system startup:

sudo systemctl enable docker

Step 4: Troubleshooting Tips

  • Docker daemon not running: Check with sudo systemctl status docker. Start it with sudo systemctl start docker.
  • Firewall blocking Docker network: Adjust firewall rules to allow Docker network traffic.
  • SELinux issues on CentOS/Fedora: If problems arise, try setting SELinux to permissive mode or configuring proper policies.
  • Proxy environment: If behind a proxy, set Docker daemon proxy settings.

Conclusion

Installing Docker on Linux can seem straightforward, but different distributions come with nuanced steps that matter for a smooth experience. By following this step-by-step guide tailored to your Linux flavor, you can set up Docker quickly and reliably—laying a solid foundation for containerized development, testing, and production deployments.

Start testing your first containers today, and enjoy the power and flexibility Docker brings to your Linux environments!


If you found this helpful, share your experience or questions below. Happy Dockering! 🚢🐳