Setting Up Docker on Ubuntu
Step-by-step guide to installing Docker and Docker Compose on Ubuntu 22.04+.
3 min read
Docker is the standard way to run self-hosted apps. This guide gets Docker and Docker Compose installed on Ubuntu 22.04 or 24.04. The steps work on any Ubuntu-based VPS.
Prerequisites
- A fresh Ubuntu 22.04 or 24.04 server
- SSH access as a user with sudo
- 5–10 minutes
Step 1: SSH In and Update
ssh root@your-server-ip
# or: ssh your-user@your-server-ip
Update the system:
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker via Official Script
The Docker team provides a convenience script that adds their repo and installs the latest version. For production, you could pin a specific version—for most self-hosting use cases, the script is fine.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Add your user to the docker group so you don't need sudo for every Docker command:
sudo usermod -aG docker $USER
Log out and back in (or run newgrp docker) for the group change to take effect.
Step 3: Install Docker Compose Plugin
Docker Compose v2 is a plugin, not a standalone binary. Install it:
sudo apt install docker-compose-plugin -y
Verify:
docker compose version
You should see something like Docker Compose version v2.x.x.
Step 4: Verify Installation
docker run hello-world
You should see "Hello from Docker!" and a message that your installation appears to be working.
Check that the Docker daemon starts on boot:
sudo systemctl enable docker
sudo systemctl status docker
Status should show active (running).
Basic Docker Commands
You'll use these constantly:
| Command | Purpose |
|---|---|
docker compose up -d | Start services in the background |
docker compose down | Stop and remove containers |
docker compose ps | List running containers |
docker compose logs -f | Follow logs |
docker compose pull | Pull latest images |
docker compose up -d --pull always | Pull and restart with new images |
Example: Run a Simple App
Create a directory and a minimal Compose file:
mkdir -p ~/test-app && cd ~/test-app
Create docker-compose.yml:
services:
nginx:
image: nginx:alpine
ports:
- "8080:80"
Run it:
docker compose up -d
Visit http://your-server-ip:8080 and you should see the default Nginx page. Stop it with docker compose down.
Troubleshooting
Permission denied when running docker: Make sure you're in the docker group and have logged out/in. Or use sudo docker.
Port already in use: Another service is using the port. Change the port mapping (e.g., 8081:80) or stop the conflicting service.
Out of disk space: Docker images and containers use disk. Run docker system prune -a to remove unused images (warning: removes all unused images, not just old ones).
Next Steps
With Docker installed, you're ready to set up a reverse proxy. The next guide covers configuring Traefik so you can serve multiple apps on different subdomains with automatic HTTPS.