1. Prerequisites
Before starting, uninstall any old versions of Docker (likedocker, docker.io, or docker-engine) to avoid conflicts:
2. Installation on Ubuntu / Debian
Ubuntu is the most popular platform for Docker. Here is how to set it up:Step 1: Update and Install Dependencies
Step 2: Add Docker’s Official GPG Key
This ensures the software you’re downloading is authentic.Step 3: Set up the Repository
Step 4: Install Docker Engine
3. Installation on CentOS / RHEL
For Red Hat-based systems, use theyum-utils package.
- Install yum-utils:
sudo yum install -y yum-utils - Add Repo:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - Install:
sudo yum install docker-ce docker-ce-cli containerd.io - Start Docker:
sudo systemctl start docker
4. Post-Installation Steps (Important)
By default, you needsudo to run Docker commands. To run Docker as a non-root user, add your user to the docker group:
- Create the group:
sudo groupadd docker(usually already exists). - Add your user:
sudo usermod -aG docker $USER - Apply changes: Log out and log back in, or run
newgrp docker.