Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What You Need

  • A 64-bit Ubuntu release that Docker supports: the current LTS releases, such as 22.04 and 24.04, are on Docker's list.
  • A user with sudo rights.
  • A KVM-based VPS or a dedicated server: Docker needs its own kernel features, which container-based virtual servers may not offer.

Ubuntu's own repository also has a package called docker.io. It is maintained by Ubuntu and is often older; the steps below install Docker's own packages instead.

Step 1: Remove Conflicting Packages

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

On a fresh server apt may answer that none of these are installed. That is fine.

Step 2: Add Docker's Repository

First the signing key:

sudo apt update
sudo apt install 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

Then the repository itself:

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

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

This installs the engine, the command-line client, the container runtime, and the Buildx and Compose plugins. On Ubuntu the service starts by itself and is enabled at boot. Check it:

sudo systemctl status docker

Step 4: Run a Test Container

sudo docker run hello-world

Docker downloads a small test image, runs it, prints a confirmation message, and exits. If you see the message, the installation works.

Step 5: Run Docker Without sudo (Optional)

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

Log out and back in to make the change permanent. Be aware of what this does: Docker's documentation states that the docker group grants root-level privileges to the user. Add only accounts you would trust with root.

First Commands

CommandWhat it does
docker run -d -p 8080:80 --name web nginxStarts an Nginx container in the background, reachable on port 8080.
docker psLists running containers; docker ps -a includes stopped ones.
docker logs webShows a container's output.
docker stop web / docker rm webStops and removes a container.
docker compose up -dStarts every service defined in compose.yaml in the current folder.
docker system dfShows the disk space images and containers use.

Docker and Your Firewall

This catches many people: a port you publish with -p is opened by Docker's own rules and bypasses ufw and firewalld. A database started with -p 3306:3306 is reachable from the internet even if ufw denies that port. To keep a service private, bind it to the server itself:

docker run -d -p 127.0.0.1:3306:3306 mysql

Custom filtering for container traffic belongs in the DOCKER-USER chain, as Docker's documentation describes.

Keep It Updated

Docker now updates with the rest of the system: sudo apt update && sudo apt upgrade. Containers keep their data in volumes; back those up like any other data. To see how much space images take over time, see how to check disk space in Linux.

Was this answer helpful?
Loading...