Docker packages an application and everything it needs into a container that runs identically on any machine — no more “works on my laptop”. On a VPS it means you can run multiple isolated apps (a website, a database, a game server) on one Ubuntu 24.04 host without dependency conflicts. This guide installs the official Docker Engine and the modern Docker Compose plugin the right way — from Docker's own repository, not the outdated docker.io snap or apt package.
Step 1 — Add Docker's official repository
sudo apt update sudo apt install ca-certificates curl -y 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 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \ https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Step 2 — Install Docker Engine and Compose
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Step 3 — Verify with hello-world
sudo docker run hello-world
Step 4 — Run Docker without sudo (optional)
sudo usermod -aG docker $USER newgrp docker # or log out and back in docker ps
docker group is effectively root access to the host — grant it only to administrators you fully trust.Step 5 — Your first real deployment with Compose
Compose describes multi-container apps in one YAML file. Example — WordPress with MySQL:
services:
db:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wp
MYSQL_PASSWORD: Str0ng-Pass!
MYSQL_RANDOM_ROOT_PASSWORD: '1'
volumes:
- db_data:/var/lib/mysql
wordpress:
image: wordpress:latest
restart: always
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp
WORDPRESS_DB_PASSWORD: Str0ng-Pass!
WORDPRESS_DB_NAME: wordpress
volumes:
db_data:
docker compose up -d docker compose ps
Your WordPress is now on port 8080. Put Nginx in front as a reverse proxy with a Lets Encrypt certificate for production.
Essential daily commands
docker ps -a # all containers docker logs -f <name> # follow a container's logs docker exec -it <name> bash # shell inside a container docker compose down # stop the stack docker system prune -a # reclaim disk from unused images
Containers and images eat disk fast — if the server fills up, see how to free disk space on Ubuntu.
Related Ubuntu guides
- Initial Ubuntu 24.04 Server Setup Guide: Secure Your New VPS in 10 Steps
- How to Install a LEMP Stack (Nginx, MySQL, PHP) on Ubuntu 24.04
- How to Get a Free SSL Certificate on Ubuntu with Lets Encrypt and Certbot
- How to Check and Free Up Disk Space on Ubuntu Server
Prefer to have experts handle it?
LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.