RUEN
To articles
Free Setup

Installing Docker on Ubuntu 22.04

Vast Sale editorial, 7 min

Docker is an open-source containerization platform. It packages an application with all its libraries into a container and runs it the same way on any machine. One computer can hold many containers, and they don't interfere with each other or with the host system.

Which Ubuntu versions are supported

According to Docker's official documentation you need 64-bit Ubuntu, one of:

  • Ubuntu 25.10 (Questing)
  • Ubuntu 25.04 (Plucky)
  • Ubuntu 24.04 LTS (Noble)
  • Ubuntu 22.04 LTS (Jammy)

Check your version:

code
lsb_release -a
Ubuntu 22.04.5 LTS, codename jammy
Ubuntu 22.04.5 LTS, codename jammy
All commands below run as root. If you're a regular user, prefix each command with sudo.

Step 1. Remove unofficial packages

Ubuntu's repository has its own builds: docker.io, docker-compose, docker-compose-v2, docker-doc, docker-buildx, podman-docker, plus containerd and runc. They conflict with Docker's official packages, so remove them before installing. If none are present, the command simply does nothing.

code
apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
Images, containers and volumes in /var/lib/docker are not removed by this.

Step 2. Preparation

Update the package list and install two packages: curl to download the key and ca-certificates to verify HTTPS certificates. On Ubuntu 22.04 they are usually already there. apt-transport-https and software-properties-common, often recommended by older guides, aren't needed for this install.

code
apt update
apt install -y ca-certificates curl

Check that the packages are installed (ii at the start of the line means installed):

code
dpkg -l curl ca-certificates gnupg | tail -n +4
Packages installed — lines start with ii
Packages installed — lines start with ii

Step 3. Docker key and repository

Download Docker's GPG key — apt uses it to verify that packages are signed by Docker — and add the repository in the modern .sources format. The architecture and the Ubuntu codename are filled in automatically, so the same commands work on 24.04 too.

code
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc

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

apt update

Check that Docker packages now come from download.docker.com:

code
apt-cache madison docker-ce | head -4
Available docker-ce versions from the official repository
Available docker-ce versions from the official repository
If download.docker.com is unreachable from your ISP, you'll need to install through a VPN.

Step 4. Install Docker

Install Docker itself, the CLI, containerd and two plugins — buildx (image builds) and compose (running several containers from one file):

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

The service starts by itself and is enabled at boot. Check the status — it should say active (running):

code
systemctl status docker --no-pager
The docker service is running and enabled at boot
The docker service is running and enabled at boot

Final check — a test container. Docker pulls the tiny hello-world image and prints a greeting:

code
docker run hello-world
...
Hello from Docker!
This message shows that your installation appears to be working correctly.

Step 5. Docker Compose

When a project needs several containers at once — say a backend, a frontend and a database — managing them one by one is inconvenient. Docker Compose describes all services in a single docker-compose.yml and brings them up with one command.

Compose was already installed in step 4 as a plugin and is called with a space — docker compose:

code
docker compose version
docker buildx version
Compose and Buildx plugins installed
Compose and Buildx plugins installed
Don't install the docker-compose package from Ubuntu's repository (apt install docker-compose). It's Compose v1 written in Python, long abandoned, and it pulls in the conflicting docker.io.

Running Docker without sudo

By default docker commands only work as root. To let a regular user run them without sudo, add the user to the docker group and log in again:

code
usermod -aG docker имя_пользователя     # username
# перезайти в систему, затем проверить / log out and back in, then check:
docker run hello-world
A member of the docker group effectively gets root on the machine. Only add people you fully trust.

How to remove Docker completely

code
apt purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
rm -rf /var/lib/docker /var/lib/containerd     # удалит все образы, контейнеры и тома / deletes all images, containers and volumes
rm /etc/apt/sources.list.d/docker.sources /etc/apt/keyrings/docker.asc

Summary

  • Install Docker from the official download.docker.com repository, not the docker.io package.
  • Compose is the docker compose plugin; the separate docker-compose package isn't needed.
  • Check: systemctl status docker and docker run hello-world.

Need help with the move?

Turnkey setup with a launch guarantee.

View services

GPU market news and breakdowns — in our Telegram channel @flux_vast_news

© Vast Sale · Source: https://vast.sale/articles/a22
Copying, paraphrasing and AI processing are permitted only with an active link to https://vast.sale