>_ blog · devops

How To Install Docker on Ubuntu 22.04

Install Docker Engine, Compose and Buildx on Ubuntu 22.04 the official way — plus the security and log settings most guides leave out.

Version:Ubuntu 22.04 LTS
SupportedBy DevNextBD Team2 min read

What's different in Ubuntu 22.04 LTS

  • Standard security updates end on 1 June 2027 — plan a move to 24.04 or 26.04
  • Docker's repository suite for this release is jammy
  • The same commands work; containers and images move unchanged to a newer Ubuntu

Supported until 1 June 2027

Docker packages an application with everything it needs, so it runs the same on your laptop and on every server. This guide installs Docker Engine with the Compose and Buildx plugins on Ubuntu 22.04 LTS (Jammy Jellyfish) from Docker's own repository, then covers the settings people usually discover too late: who can run Docker, how published ports interact with the firewall, and log rotation.

Prerequisites

  • A server running Ubuntu 22.04, 64-bit (x86_64 or arm64).
  • A user with sudo rights.
  • The UFW firewall enabled with SSH allowed.

Step 1 — Remove conflicting packages

Ubuntu's own docker.io package and similar tools conflict with Docker's official packages. Remove any that exist (apt may say none are installed — that's fine):

Server
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove -y $pkg; done

Existing images and containers in /var/lib/docker/ are not deleted by this step.

Step 2 — Add Docker's repository

Add Docker's signing key and its repository. The Suites line reads your release's codename automatically — on Ubuntu 22.04 it becomes jammy:

Server
sudo apt update
sudo apt install -y ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

Step 3 — Install Docker Engine

Server
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

The service starts automatically. Check it, and run the test image:

Server
sudo systemctl status docker --no-pager
sudo docker run --rm hello-world
Output
Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 4 — Run Docker without sudo (understand the risk)

Adding your user to the docker group lets you run docker without sudo:

Server
sudo usermod -aG docker $USER
newgrp docker
docker ps

Step 5 — Published ports bypass UFW

When you publish a port with -p 8080:80, Docker writes its own firewall rules, and UFW does not block that port. Many servers are exposed this way by accident. Publish services that sit behind a reverse proxy on localhost only:

Server
docker run -d --name web -p 127.0.0.1:8080:80 nginx:stable

Then let your reverse proxy (nginx, Caddy) on the host forward public traffic to 127.0.0.1:8080. Publish a port on all interfaces only when you really want it open to the internet.

Step 6 — Rotate container logs

By default, container logs can grow until the disk is full. Switch to Docker's local log driver, which compresses and rotates logs, in /etc/docker/daemon.json:

daemon.json
{
  "log-driver": "local",
  "log-opts": { "max-size": "20m", "max-file": "5" }
}
Server
sudo systemctl restart docker

The new settings apply to containers created after the restart.

Step 7 — Use Docker Compose

Compose describes several containers in one file. Create compose.yaml:

compose.yaml
services:
  app:
    image: nginx:stable
    ports:
      - "127.0.0.1:8080:80"
    restart: unless-stopped
Server
docker compose up -d
docker compose ps

Keeping Docker up to date

Docker updates arrive through apt with the rest of the system:

Server
sudo apt update && sudo apt upgrade -y

Clean up unused images and stopped containers from time to time with docker system prune (it asks before deleting).

Conclusion

Docker Engine, Compose and Buildx are now installed on Ubuntu 22.04, with safe defaults for permissions, ports and logs. Ubuntu 22.04 receives standard security updates until 1 June 2027 — plan your next server move well before then.

All versions of this guide

Each version is a complete guide written and tested for that release.

VersionStatusSupported untilGuide
Ubuntu 26.04 LTSCurrent29 May 2031Open
Ubuntu 24.04 LTSSupported31 May 2029Open
Ubuntu 22.04 LTSSupported1 June 2027You're reading this

#Docker#Ubuntu#Linux#DevOps