DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Docker Tutorial

Introduction to docker
Why Use Docker?
Docker vs Virtual Machines
Installing Docker
Key Docker Concepts
Docker Images
Docker Containers
Writing Dockerfiles
Docker Volumes

Installing Docker on Linux

PreviousPrev
Next

Complete guide to installing Docker Engine on Linux distributions. Learn how to install Docker on Ubuntu, Debian, CentOS, and configure it properly.

Prerequisites

Before installing Docker on Linux, ensure your system meets these requirements:

Linux Requirements

  • 64-bit OS: Most modern distributions supported
  • Kernel: Version 3.10 or higher
  • RAM: Minimum 2GB (4GB recommended)
  • Storage: 10GB minimum for Docker images and containers

Installing Docker on Ubuntu/Debian

Step 1: Update Package Index

sudo apt-get update

Step 2: Install Prerequisites

sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Step 3: Add Docker's Official GPG Key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Step 4: Set Up Repository

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.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-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 6: Verify Installation

sudo docker run hello-world

Installing Docker on CentOS/RHEL

Step 1: Install Required Packages (CentOS)

sudo yum install -y yum-utils

Step 2: Add Docker Repository (CentOS)

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 3: Install Docker (CentOS)

sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 4: Start Docker (CentOS)

sudo systemctl start docker
sudo systemctl enable docker

Step 5: Verify Installation (CentOS)

sudo docker run hello-world

Installing Docker on Fedora

Step 1: Install Prerequisites (Fedora)

sudo dnf -y install dnf-plugins-core

Step 2: Add Docker Repository (Fedora)

sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo

Step 3: Install Docker (Fedora)

sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 4: Start Docker (Fedora)

sudo systemctl start docker
sudo systemctl enable docker

Step 5: Verify Installation (Fedora)

sudo docker run hello-world

Post-Installation Steps

Running Docker Without sudo

By default, Docker requires root privileges. To run Docker as a non-root user:

Step 1: Create Docker Group

sudo groupadd docker

Step 2: Add Your User to Docker Group

sudo usermod -aG docker $USER

Step 3: Log Out and Back In

For the changes to take effect, log out and log back in. Or run:

newgrp docker

Step 4: Verify

docker run hello-world

You should now be able to run Docker commands without sudo.

Configure Docker to Start on Boot

Ubuntu/Debian/Fedora (systemd)

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

CentOS/RHEL 7 and earlier

sudo chkconfig docker on

Configure Docker Daemon

Create or edit /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2"
}

Restart Docker after making changes:

sudo systemctl restart docker

Troubleshooting Linux Installation

Docker Service Not Starting

Problem: "Failed to start docker.service"

Solution:

# Check service status
sudo systemctl status docker

# View logs
sudo journalctl -u docker

# Restart service
sudo systemctl restart docker

Permission Denied Error

Problem: "Got permission denied while trying to connect to the Docker daemon socket"

Solution:

  1. Add user to docker group: sudo usermod -aG docker $USER
  2. Log out and back in
  3. Or use: newgrp docker

Firewall Issues

Problem: Cannot pull images due to firewall

Solution:

# For firewalld
sudo firewall-cmd --permanent --zone=trusted --add-interface=docker0
sudo firewall-cmd --reload

# For UFW
sudo ufw allow 2375/tcp
sudo ufw allow 2376/tcp

Storage Driver Issues

Problem: "Error starting daemon: error initializing graphdriver"

Solution:

  1. Check available storage drivers: docker info
  2. Set appropriate driver in /etc/docker/daemon.json
  3. Common drivers: overlay2 (recommended), aufs, devicemapper

Testing Your Installation

Let's verify everything works correctly:

1. Check Docker Version

docker --version
docker compose version

2. View System Information

docker info

This displays:

  • Number of containers (running, paused, stopped)
  • Number of images
  • Storage driver information
  • System resources

3. Run a Test Container

docker run -d -p 8080:80 nginx

Then visit http://localhost:8080 in your browser or use curl:

curl http://localhost:8080

You should see the Nginx welcome page!

4. List Running Containers

docker ps

5. Stop and Remove the Container

docker stop $(docker ps -q)
docker rm $(docker ps -aq)

Linux-Specific Configuration

SELinux Considerations (CentOS/RHEL/Fedora)

If using SELinux:

# Check SELinux status
getenforce

# Set SELinux to permissive mode for testing
sudo setenforce 0

# Make it permanent (edit /etc/selinux/config)
SELINUX=permissive

For production, configure proper SELinux policies instead of disabling it.

AppArmor Considerations (Ubuntu/Debian)

Docker works with AppArmor by default. If you encounter issues:

# Check AppArmor status
sudo aa-status

# Reload AppArmor profiles
sudo systemctl reload apparmor

Resource Limits

Configure resource limits in /etc/docker/daemon.json:

{
  "default-ulimits": {
    "nofile": {
      "Name": "nofile",
      "Hard": 64000,
      "Soft": 64000
    }
  }
}

Docker Compose on Linux

Docker Compose is now included as a plugin. Verify:

docker compose version

If you need standalone Docker Compose:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Best Practices for Linux

1. Keep Docker Updated

# Ubuntu/Debian
sudo apt-get update && sudo apt-get upgrade docker-ce docker-ce-cli

# CentOS/RHEL
sudo yum update docker-ce docker-ce-cli

# Fedora
sudo dnf upgrade docker-ce docker-ce-cli

2. Monitor Resource Usage

# View container resource usage
docker stats

# View disk usage
docker system df

3. Clean Up Regularly

# Remove unused images
docker image prune

# Remove all unused resources
docker system prune -a

4. Configure Logging

Prevent logs from filling disk:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

5. Use systemd for Management

# Start Docker
sudo systemctl start docker

# Stop Docker
sudo systemctl stop docker

# Restart Docker
sudo systemctl restart docker

# View Docker status
sudo systemctl status docker

Uninstalling Docker

If you need to remove Docker:

Ubuntu/Debian

sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

CentOS/RHEL/Fedora

sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd

What's Next?

Now that Docker is installed on Linux, you can:

  • Learn about Docker images and containers
  • Build your first Docker application
  • Explore Docker Compose for multi-container apps
  • Set up production Docker deployments
  • Configure Docker Swarm for orchestration

Your Docker journey on Linux has begun!

PreviousPrev
Next

Continue Learning

Installing Docker

Step-by-step guide to installing Docker on Windows, macOS, and Linux. Set up Docker Desktop and verify your installation for a smooth development experience.

20 min·Easy

Installing Docker on Windows

Complete guide to installing Docker Desktop on Windows. Learn how to set up WSL 2, install Docker Desktop, and configure your Windows development environment.

20 min·Easy

Installing Docker on macOS

Complete guide to installing Docker Desktop on macOS. Learn how to set up Docker on both Intel and Apple Silicon Macs for native performance.

15 min·Easy

Explore Related Topics

Ku

Kubernetes Tutorials

Orchestrate your Docker containers at scale

CI

CI/CD Tutorials

Automate Docker builds and deployments in pipelines

Try the Tool

Dockerfile Linter

Instantly lint your Dockerfile for best-practice violations and security issues.

On This Page

PrerequisitesLinux RequirementsInstalling Docker on Ubuntu/DebianStep 1: Update Package IndexStep 2: Install PrerequisitesStep 3: Add Docker's Official GPG KeyStep 4: Set Up RepositoryStep 5: Install Docker EngineStep 6: Verify InstallationInstalling Docker on CentOS/RHELStep 1: Install Required Packages (CentOS)Step 2: Add Docker Repository (CentOS)Step 3: Install Docker (CentOS)Step 4: Start Docker (CentOS)Step 5: Verify Installation (CentOS)Installing Docker on FedoraStep 1: Install Prerequisites (Fedora)Step 2: Add Docker Repository (Fedora)Step 3: Install Docker (Fedora)Step 4: Start Docker (Fedora)Step 5: Verify Installation (Fedora)Post-Installation StepsRunning Docker Without sudoConfigure Docker to Start on BootConfigure Docker DaemonTroubleshooting Linux InstallationDocker Service Not StartingPermission Denied ErrorFirewall IssuesStorage Driver IssuesTesting Your Installation1. Check Docker Version2. View System Information3. Run a Test Container4. List Running Containers5. Stop and Remove the ContainerLinux-Specific ConfigurationSELinux Considerations (CentOS/RHEL/Fedora)AppArmor Considerations (Ubuntu/Debian)Resource LimitsDocker Compose on LinuxBest Practices for Linux1. Keep Docker Updated2. Monitor Resource Usage3. Clean Up Regularly4. Configure Logging5. Use systemd for ManagementUninstalling DockerUbuntu/DebianCentOS/RHEL/FedoraWhat's Next?