What you need
- Ubuntu 20.04, 22.04 or newer.
- Root or sudo access.
- An internet connection.
- Docker (step 2 installs it).
Step 1: Update Ubuntu
sudo apt update && sudo apt upgrade -y
Step 2: Install Docker
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
docker --version
(For the newest Docker version, use the official Docker repository instead of docker.io.)
Step 3: Install Docker Compose
Install the Compose plugin:
sudo apt install docker-compose-plugin
If the package is not found, add the official Docker repository first, or install docker-compose-v2:
sudo apt install docker-compose-v2
Check it:
docker compose version
Step 4: Create a Compose file
mkdir docker-project
cd docker-project
nano docker-compose.yml
Add:
services:
web:
image: nginx
ports:
- "8080:80"
(The line version: '3' is no longer needed in current Compose versions.)
Start it in the background:
docker compose up -d
Open http://your_server_ip:8080. You see the Nginx welcome page.
Step 5: Manage the containers
| Command | What it does |
|---|---|
docker compose up -d | Starts the services in the background |
docker compose down | Stops and removes the containers and the network |
docker ps | Lists the running containers |
docker compose logs | Shows the logs |
docker compose ps | Shows the services of the project |
docker compose restart | Restarts the services |
docker compose pull | Downloads newer images |
Why Compose is useful
- One file for the whole app. Web server, database, cache and more.
- Repeatable. The same setup works on every machine.
- Easy to share. Put the file in Git.
- Simple commands to start and stop everything.
Quick recap
- Install Docker and the
docker-compose-plugin. - Write
docker-compose.yml. - Use
docker compose up -danddocker compose down.