Set up Docker and Docker Compose
The quickest start is the Docker CE image, which boots with Docker Engine and Compose ready; on any other image you install them from the official Docker repository in a few commands. This guide then runs a real two-container stack and covers the settings that matter on a public server.
Should you use the Docker image or install it yourself?
Pick the Docker CE image when you create or rebuild the server and Docker is already installed on Ubuntu 24.04. Install it yourself when you prefer Debian, Rocky or Alma, or when the server already runs other things. Both paths end with the same packages from the official Docker repository, which are newer than the docker.io package in the Ubuntu and Debian archives.
Size the plan by the containers you run. A reverse proxy plus one small app fits in P2 with 1 vCPU, 2 GB RAM, 40 GB NVMe. A typical stack with a web app, PostgreSQL and Redis wants 4 GB, for example S4 at $4.25 a month in Europe. Arm plans such as A8 run Docker equally well when every image offers an arm64 build.
How do you install Docker on Ubuntu or Debian?
Add the Docker repository and key, then install the engine and the Compose plugin:
apt update
apt install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
echo "deb [signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" > /etc/apt/sources.list.d/docker.list
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginOn Debian, replace both linux/ubuntu parts with linux/debian. The line in docker.list ties the repository to your release name, such as noble on Ubuntu 24.04 or trixie on Debian 13.
Verify with docker run --rm hello-world, which pulls a tiny image and prints a greeting, and docker compose version.
How do you install Docker on Rocky Linux or AlmaLinux?
Use the CentOS repository that Docker publishes for Red Hat compatible systems:
dnf install -y dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now dockerIf Podman packages from the base system are installed, dnf may report conflicts; remove them first with dnf remove -y podman buildah. Then run the same hello-world test.
To let your sudo user run Docker without sudo, add it to the docker group with usermod -aG docker deploy and log in again. Keep in mind that membership of that group is equal to root access on the server.
What does a practical compose.yaml look like?
Keep each project in its own folder, for example /srv/app, with a compose.yaml and a .env file for secrets. This stack runs a web app with PostgreSQL:
services:
web:
image: ghcr.io/example/app:1.4.2
restart: unless-stopped
env_file: .env
ports:
- "127.0.0.1:3000:3000"
depends_on:
db:
condition: service_healthy
db:
image: postgres:17
restart: unless-stopped
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- dbdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
volumes:
dbdata:Put POSTGRES_PASSWORD= and a long random value in .env (generate one with openssl rand -hex 24) and set chmod 600 .env. Start the stack with docker compose up -d, check it with docker compose ps, and follow logs with docker compose logs -f web.
Pin image tags such as 1.4.2 or 17 rather than latest, so an update only happens when you choose. The restart: unless-stopped line brings containers back after a reboot from the console.
How do you keep container ports off the internet?
Publish ports on 127.0.0.1 only, as in the example, and let a reverse proxy on the host or in another container serve the public 80 and 443. A line like "3000:3000" without an address listens on every interface, and Docker opens it in netfilter itself, so ufw and firewalld rules do not stop it.
The database in the example publishes nothing at all: the web container reaches it as db:5432 over the internal network that Compose creates for the project. Check what is exposed with docker ps --format "table {{.Names}}\t{{.Ports}}" and from outside with an nmap scan, as shown in the firewall guide.
If a port must be public but limited to one source, add a rule to the DOCKER-USER chain, for example iptables -I DOCKER-USER -p tcp --dport 5432 ! -s 198.51.100.7 -j DROP, and make it persistent with your firewall tool.
How do you stop logs and images from filling the disk?
By default Docker keeps container logs forever, and old images pile up after every update. Limit logs for all containers in /etc/docker/daemon.json:
{
"log-driver": "local",
"log-opts": { "max-size": "20m", "max-file": "3" }
}Restart Docker with systemctl restart docker and recreate containers with docker compose up -d --force-recreate so they pick up the new setting. Check space with docker system df, and clean unused images with docker image prune -a after each update. On a 40 GB disk like the one on S4 this is worth a weekly cron job.
How do you update a stack safely?
Change the tag in compose.yaml, pull, then recreate only what changed:
cd /srv/app
docker compose pull
docker compose up -d
docker compose psCompose replaces containers whose image changed and leaves the rest running. Before a database major version change, such as PostgreSQL 16 to 17, dump the data first with docker compose exec db pg_dumpall -U postgres > /srv/backup/all.sql, because new major versions cannot read old data folders directly.
Update Docker Engine itself through the system package manager with the rest of the server. Containers restart during an engine upgrade, so do it at a quiet hour.
Where does container data live, and how do you back it up?
Named volumes such as dbdata live under /var/lib/docker/volumes/. Bind mounts like ./uploads:/app/uploads live in your project folder, which makes them easier to see and copy. For a backup, dump databases with their own tools from inside the container, then back up the project folder and the dumps with restic or borg, as described in backups and restore. Copying a running database volume file by file is not a safe backup.
Questions about this guide
Is Docker Compose included in the Docker CE image?
Yes. The image ships Docker Engine with the Compose plugin, so docker compose up -d works right after the first login.
Should I use docker-compose or docker compose?
Use docker compose with a space, the plugin that ships with current Docker. The old standalone docker-compose program is no longer developed.
Can I run Docker on the Arm plans?
Yes. Ampere Altra runs arm64 images, and most popular images publish one. Check an image with docker manifest inspect before you rely on it.
Why can people reach my container even though ufw blocks the port?
Docker adds its own netfilter rules for published ports. Publish on 127.0.0.1 and put a reverse proxy in front, or filter in the DOCKER-USER chain.
How much RAM does a small Docker stack need?
A proxy and one app run in 2 GB; an app with PostgreSQL and Redis is more comfortable with 4 GB. Check real usage with docker stats after a few days.
Is Kubernetes available?
There is no managed Kubernetes service. You can install a light distribution such as k3s yourself, but Compose is the simpler choice for one server.