Docker Installation and Configuration on Ubuntu 16.x–24.x LTS
Overview
This guide describes a unified, extensible, and secure workflow for installing Docker Engine (CE) on Ubuntu 16.x, 18.x, 20.x, 22.x, and 24.x LTS releases. It covers:
- System preparation and prerequisites
- Official Docker repository configuration
- Docker Engine installation
- Post-installation refinements (non-root usage, user namespaces)
- Verification and basic usage
- Advanced topics: Docker Compose, private registry, security hardening
- Troubleshooting tips
Contents
- Prerequisites
- System Preparation
- Repository Setup
- Installing Docker Engine
- Post-Installation Configuration
- Manage Docker as Non-root User
- Enable User Namespaces
- Verification & Basic Usage
- Advanced Topics
- Installing Docker Compose
- Setting Up a Private Registry
- Security Hardening
- Troubleshooting
Prerequisites
- Ubuntu LTS release: 16.x, 18.x, 20.x, 22.x, or 24.x (64-bit)
- Sudo or root privileges
- Internet access
- ≥1 GB RAM and ≥2 CPU cores (recommended)
System Preparation
- Update package index
- Remove legacy Docker packages
Repository Setup
- Install dependencies
- Add Docker’s official GPG key
- (Optional) Verify fingerprint
- Configure the Docker repository
- Refresh package index
Installing Docker Engine
Install the latest Docker CE packages:
Post-Installation Configuration
Manage Docker as Non-root User
By default, Docker requires root. To run Docker commands without sudo:
Enable User Namespaces
Improve isolation by remapping container UIDs:
1. Create or edit /etc/docker/daemon.json:
Verification & Basic Usage
- Check versions
bash docker version - List containers
bash docker ps - Pull and run NGINX
bash docker pull nginx:latest docker run -d -p 80:80 nginx
Advanced Topics
Installing Docker Compose
- Download the binary:
- Make it executable:
- Verify:
bash docker-compose --version
Setting Up a Private Registry
Run the official registry image:
Security Hardening
- Enable Content Trust:
- Leverage Seccomp & AppArmor (default on Ubuntu)
- Scan images for vulnerabilities using tools like Trivy
Troubleshooting
- Permission denied on
/var/run/docker.sock
Ensure your user is in thedockergroup; log out/in. - Container start failures
Inspect logs:
bash docker logs <container> - Network conflicts
Create isolated bridge:
bash docker network create --driver bridge isolated_net docker run --network=isolated_net ... - Low disk space
Clean up unused objects:
bash docker system prune -a --volumes