Skip to content

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

  1. Prerequisites
  2. System Preparation
  3. Repository Setup
  4. Installing Docker Engine
  5. Post-Installation Configuration
  6. Manage Docker as Non-root User
  7. Enable User Namespaces
  8. Verification & Basic Usage
  9. Advanced Topics
  10. Installing Docker Compose
  11. Setting Up a Private Registry
  12. Security Hardening
  13. 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

  1. Update package index
    sudo apt-get update
    
  2. Remove legacy Docker packages
    sudo apt-get remove -y docker docker-engine docker.io containerd runc
    

Repository Setup

  1. Install dependencies
    sudo apt-get install -y \
      apt-transport-https \
      ca-certificates \
      curl \
      software-properties-common
    
  2. Add Docker’s official GPG key
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
      | sudo apt-key add -
    
  3. (Optional) Verify fingerprint
    sudo apt-key fingerprint 0EBFCD88
    
  4. Configure the Docker repository
    sudo add-apt-repository \
      "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
      $(lsb_release -cs) stable"
    
  5. Refresh package index
    sudo apt-get update
    

Installing Docker Engine

Install the latest Docker CE packages:

sudo apt-get install -y docker-ce docker-ce-cli containerd.io
Verify the Docker service:
sudo systemctl status docker


Post-Installation Configuration

Manage Docker as Non-root User

By default, Docker requires root. To run Docker commands without sudo:

sudo usermod -aG docker $USER
newgrp docker
docker run --rm hello-world

Enable User Namespaces

Improve isolation by remapping container UIDs:
1. Create or edit /etc/docker/daemon.json:

{
  "userns-remap": "default"
}
2. Restart Docker:
sudo systemctl restart docker


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

  1. Download the binary:
    sudo curl -L \
      "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" \
      -o /usr/local/bin/docker-compose
    
  2. Make it executable:
    sudo chmod +x /usr/local/bin/docker-compose
    
  3. Verify:
    bash docker-compose --version

Setting Up a Private Registry

Run the official registry image:

docker run -d \
  -p 5000:5000 \
  --restart=always \
  --name registry \
  registry:2
Push an image:
docker tag ubuntu localhost:5000/my-ubuntu
docker push localhost:5000/my-ubuntu

Security Hardening

  • Enable Content Trust:
    export DOCKER_CONTENT_TRUST=1
    
  • 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 the docker group; 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