🐳 Installing Docker on Linux (Easy Step-by-Step Guide)
Docker lets you run applications in isolated containers, making setup, deployment, and testing much easier. This guide shows the recommended, official way to install Docker on a Linux PC.
The instructions work for Ubuntu, Linux Mint, Debian, and other Debian-based distributions.
✅ Prerequisites
Before you start, make sure:
- You are running a 64-bit Linux system
- You have a user with sudo privileges
- Your system is up to date
Update your system:
sudo apt update && sudo apt upgrade -y
🧹 Step 1: Remove Old Docker Versions (If Any)
If Docker was previously installed, remove old packages to avoid conflicts:
sudo apt remove -y docker docker-engine docker.io containerd runc
🔑 Step 2: Add Docker’s Official GPG Key
Create a keyring directory:
sudo install -m 0755 -d /etc/apt/keyrings
Download and install Docker’s GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Set correct permissions:
sudo chmod a+r /etc/apt/keyrings/docker.gpg
📦 Step 3: Add Docker Repository
Add the official Docker repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo $VERSION_CODENAME) stable" \
| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Update package lists:
sudo apt update
🐋 Step 4: Install Docker Engine
Install Docker and related tools:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
▶️ Step 5: Start and Enable Docker
Start Docker now:
sudo systemctl start docker
Enable Docker at boot:
sudo systemctl enable docker
Check status:
systemctl status docker
👤 Step 6: Run Docker Without sudo (Recommended)
Add your user to the docker group:
sudo usermod -aG docker $USER
⚠️ Important: Log out and log back in (or reboot) for this to take effect.
🧪 Step 7: Test the Installation
Run the official test container:
docker run hello-world
If you see a success message, Docker is working correctly 🎉
🔧 Common Issue: Permission Denied on /var/run/docker.sock
If you see:
permission denied while trying to connect to the Docker daemon
Fix it with:
sudo usermod -aG docker $USER
logout
Then log back in and try again.
📎 Appendix: Installing Docker on Windows
Option 1: Docker Desktop (Recommended)
- Enable WSL2 in Windows
Open PowerShell (Admin):wsl --install - Reboot when prompted
- Download Docker Desktop for Windows from Docker’s website
- During setup:
- Enable “Use WSL 2 backend”
- Allow installer to add required components
- After installation, open Docker Desktop
- Test in PowerShell or WSL:
docker run hello-world
Option 2: Using Docker Inside WSL (Advanced)
- Install Ubuntu via Microsoft Store
- Follow the Linux instructions above inside WSL
- Ensure Docker Desktop is not running simultaneously
✅ Summary
- Linux: Install Docker via the official Docker repository
- Avoid Snap/Flatpak Docker installs for production use
- Add your user to the
dockergroup to avoidsudo - Windows users should use Docker Desktop + WSL2