Installing Docker and Docker Compose on Ubuntu, step by step
Install Docker Engine from the official repository, use it without root, run your first container and manage multi-app stacks with Compose.
Tutorials · 3 min read
Docker runs applications together with their dependencies inside isolated containers. It is the most practical way to host many services on one server without conflicts. This guide installs Docker Engine and Docker Compose from the official repository on Ubuntu 24.04.
Prerequisites
- A cloud server running Ubuntu 22.04 or 24.04 and a user with
sudorights (see Connecting with SSH). - The system should be up to date:
sudo apt update && sudo apt upgrade -y
1. Add the official repository
sudo apt install -y 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
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
sudo apt update
2. Install Docker Engine
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker
docker --version
docker compose version
3. Verify the installation
sudo docker run --rm hello-world
If you see “Hello from Docker!” the installation is complete.
4. Use it without root (optional)
sudo usermod -aG docker $USER
newgrp docker
Security note: a user in the docker group effectively has root rights. Add only users you trust.
5. Your first Compose file
Create a folder and write a compose.yaml in it. Example: a simple web server.
services:
web:
image: nginx:alpine
restart: unless-stopped
ports:
- "8080:80"
docker compose up -d # start
docker compose ps # status
docker compose logs -f # logs
docker compose down # stop and remove
At http://SERVER_IP:8080 you will see the Nginx welcome page. For real applications use a reverse proxy instead of exposing ports straight to the internet: automatic HTTPS with Caddy.
Useful commands
| Command | What it does |
|---|---|
docker ps -a | Lists all containers |
docker compose pull && docker compose up -d | Updates images and restarts |
docker system df | Shows disk usage |
docker system prune -a | Cleans unused images and containers (use with care) |
Things to watch
- Docker can publish ports bypassing the firewall (UFW); publish only the ports you need and put them behind a reverse proxy (the
127.0.0.1:8080:80form allows local access only). - Keep data in volumes, not inside the container; otherwise data is lost when the container is removed.
- Take regular snapshots and off-server backups.
Start with Melinhost
A cloud server with 4 vCPU and 8 GB RAM is a good start for Docker. Full root access lets you build your environment exactly as you like.