Docker Curriculum
On this page
- Install Linux
- Prerequisites
- Method 1: Official Docker Repository (Recommended)
- On Ubuntu and Debian
- On CentOS, RHEL, and Amazon Linux 2
- On Amazon Linux 2023
- Method 2: Convenience Script
- Method 3: Installing a Specific Version
- On Ubuntu/Debian — List available versions:
- Prevent automatic upgrades
- Post-Installation Configuration
- Run Docker Without sudo
- Configure Docker to Start on Boot
- Configure Log Rotation
- Configure Docker Data Directory
- Verifying Your Installation
- Common Installation Issues
- Issue: "Got permission denied while trying to connect to the Docker daemon socket"
- Issue: Docker service fails to start
- Issue: "Cannot connect to the Docker daemon"
- Issue: Insufficient disk space
- Summary
Install Linux
Linux is the primary operating system for running Docker in production. Whether you are setting up a development server, configuring an AWS EC2 instance, or preparing a CI/CD runner, the ability to install and configure Docker on Linux is a core DevOps skill.
This file covers three installation methods for the most common Linux distributions. You will also learn how to verify the installation, configure post-install settings, and troubleshoot common problems.
Prerequisites
Before installing Docker, confirm the following:
- You are running a 64-bit Linux distribution
- Your kernel version is 3.10 or higher (check with
uname -r) - You have
sudoprivileges - Your system has internet access
Method 1: Official Docker Repository (Recommended)
This is the recommended method. It gives you the latest stable Docker version and automatic updates through your package manager.
On Ubuntu and Debian
Step 1: Remove any old versions
Old or unofficial Docker packages can conflict with the official installation. Remove them first.
Do not worry if the command reports that none of these packages are installed. That is fine.
Step 2: Update the package index and install dependencies
Step 3: Add Docker's official GPG key
The GPG key ensures packages you download are genuine and have not been tampered with.
Step 4: Add the Docker repository
Step 5: Install Docker Engine
This installs:
docker-ce— Docker Engine (the daemon)docker-ce-cli— Docker CLIcontainerd.io— the container runtimedocker-buildx-plugin— extended build capabilitiesdocker-compose-plugin— Docker Compose v2
Step 6: Verify the installation
You should see output that ends with:
On CentOS, RHEL, and Amazon Linux 2
Step 1: Remove old versions
Step 2: Install the yum-utils package
Step 3: Add the Docker repository
Step 4: Install Docker Engine
Step 5: Start and enable Docker
Step 6: Verify
On Amazon Linux 2023
Amazon Linux 2023 uses dnf instead of yum:
Method 2: Convenience Script
Docker provides a script that automates the installation for development environments. It is NOT recommended for production — use the repository method for production servers.
This script detects your distribution and installs Docker automatically. Useful for quickly setting up development machines and CI runners.
Method 3: Installing a Specific Version
In production environments, you should pin Docker to a specific version to avoid unexpected changes during system updates.
On Ubuntu/Debian — List available versions:
Output:
Install a specific version:
Prevent automatic upgrades
Post-Installation Configuration
Run Docker Without sudo
By default, running Docker commands requires sudo. This is cumbersome for daily use. Add your user to the docker group to fix this.
Important: The docker group grants privileges equivalent to root. Only add trusted users to this group.
Configure Docker to Start on Boot
Configure Log Rotation
Without log rotation, container logs can fill your disk. Always configure this in production.
Create or edit /etc/docker/daemon.json:
Restart Docker to apply:
Configure Docker Data Directory
By default, Docker stores all data (images, containers, volumes) in /var/lib/docker. If your root filesystem is small, you can move this to a larger disk.
Add this to daemon.json:
Restart Docker:
Verifying Your Installation
After installation, confirm everything is working correctly.
Common Installation Issues
Issue: "Got permission denied while trying to connect to the Docker daemon socket"
Issue: Docker service fails to start
Issue: "Cannot connect to the Docker daemon"
Issue: Insufficient disk space
Summary
- The recommended installation method on Linux is through the official Docker repository — it gives you the latest version with automatic updates
- Install
docker-ce,docker-ce-cli,containerd.io,docker-buildx-plugin, anddocker-compose-plugintogether - After installation, add your user to the
dockergroup to avoid needingsudofor every command - Always enable Docker to start on boot with
systemctl enable docker - Always configure log rotation in
/etc/docker/daemon.jsonbefore running containers in production - Pin Docker to a specific version in production environments to prevent unexpected upgrades
In the next file, we cover installing Docker on macOS using Docker Desktop.