DeveloperBootstrap

Containerization

Install Docker on Ubuntu 24.04 - Production Ready

Step-by-step Docker installation with Docker Compose, security configuration, and best practices for production.

What you'll learn

  • Install Docker CE from the official Docker repository
  • Configure Docker daemon with optimal security settings
  • Install Docker Compose V2
  • Set up proper user permissions and Docker group management
  • Implement Docker security best practices
  • Verify installation and troubleshoot common issues

System Preparation

Bash
1# Update system packages
2sudo apt update && sudo apt upgrade -y
3
4# Remove old Docker packages
5sudo apt remove -y docker docker-engine docker.io containerd runc
6
7# Install prerequisites
8sudo apt install -y ca-certificates curl gnupg lsb-release
9
10# Verify system requirements
11uname -r        # Kernel >= 3.10
12df -h           # 20 GB+ free
13free -h         # 2 GB+ RAM

Install Docker Engine

Bash
1# Add Docker GPG key
2sudo install -m 0755 -d /etc/apt/keyrings
3curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
4  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
5sudo chmod a+r /etc/apt/keyrings/docker.gpg
6
7# Add Docker repository
8echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
9  https://download.docker.com/linux/ubuntu \
10  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
11  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
12
13# Install Docker
14sudo apt update
15sudo apt install -y docker-ce docker-ce-cli containerd.io \
16  docker-buildx-plugin docker-compose-plugin
17
18# Add user to docker group (avoids needing sudo)
19sudo usermod -aG docker $USER
20newgrp docker

Install Docker Compose

Docker Compose V2 is now bundled as a Docker plugin and installed with the command above. Verify it works:

Bash
1docker compose version
2# Docker Compose version v2.x.x

Security Configuration

Bash
1# /etc/docker/daemon.json — production-hardened settings
2sudo tee /etc/docker/daemon.json <<'EOF'
3{
4  "log-driver": "json-file",
5  "log-opts": { "max-size": "100m", "max-file": "3" },
6  "no-new-privileges": true,
7  "userns-remap": "default",
8  "icc": false,
9  "live-restore": true
10}
11EOF
12
13sudo systemctl restart docker

Verify & Test

Bash
1docker --version
2docker compose version
3docker run --rm hello-world
4docker info

Troubleshooting

  • Permission denied: Run newgrp docker or log out and back in after adding yourself to the docker group.
  • Cannot connect to daemon: Check sudo systemctl status docker.
  • Port already in use: Another process owns the port — use sudo ss -tulpn | grep :PORT to find it.