The fastest way: create a server with the Docker image
If you are creating a new server, choosing Docker from the image list is fastest. It starts with Docker Engine and Docker Compose installed on Ubuntu 24.04 LTS, so you can run docker compose up as soon as you log in. The app overview and recommended sizes are on the Docker VPS page.
To add Docker to a server you already use, or to use a different operating system such as Debian or AlmaLinux, install it yourself following the steps below. All commands assume you are logged in as root. If you are logged in as a regular user, add sudo before each command.
What to check before installing
Docker runs on servers of any size. For personal projects running a few containers, the smallest 12GB general plan is plenty; to run a database, web server and cache together, 24GB or more gives you room. If you download and build images a lot, an NVMe VPS with a fast disk makes a noticeable difference.
If old Docker packages from the operating system repositories are installed, remove them first so they do not mix with the official packages. Packages that are not installed are skipped, so it is fine to run as is.
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do apt remove -y $pkg; doneInstall Docker on Ubuntu 24.04
Step 1. Add the repository key and address
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
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" > /etc/apt/sources.list.d/docker.listStep 2. Install Docker Engine and Compose
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginAfter installation, the Docker service starts automatically and comes back up when the server restarts. The same commands work on Ubuntu 22.04 and 26.04 as well. The version name in the repository address is read automatically from /etc/os-release.
Install Docker on Debian 13
Debian follows the same steps as Ubuntu; only the repository address changes to linux/debian. Use the same commands on Debian 12 too.
apt update
apt install -y ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
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/debian $(. /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-pluginInstall Docker on AlmaLinux 10
AlmaLinux and Rocky Linux use Docker's RHEL repository. Clean up the preinstalled Podman first so they do not overlap, then install. The same commands work on AlmaLinux 9 and Rocky Linux 9 and 10.
dnf remove -y podman buildah runc
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now dockerWhen asked to accept the repository signing key on first install, press y. On RHEL-based systems the service does not start automatically after installation, so the last line, systemctl enable --now docker, starts it now and at every boot.
Check the install and run your first container
Start a test container once with the command below. If you see a message beginning with Hello from Docker, the engine, image download and container run are all working. --rm cleans up the container as soon as it finishes.
docker run --rm hello-world
docker compose versionTo use Docker as a regular user too, add that user to the docker group and log in again. The docker group has root-equivalent rights, so add only users you trust.
usermod -aG docker usernameDeploy services with Docker Compose
Compose lets you write container settings in a single YAML file and start them with one line. Even if you move or recreate the server, the same file brings back the same environment. For example, a file that starts a single Nginx web server looks like this.
mkdir -p /opt/web && cd /opt/web
cat > compose.yaml <<'EOF'
services:
web:
image: nginx:stable
ports:
- "80:80"
volumes:
- ./html:/usr/share/nginx/html:ro
restart: unless-stopped
EOF
docker compose up -dOpen http://YOUR_SERVER_IP in your browser to see the Nginx page. Put an index.html in the html folder and that file is shown. These four commands cover everyday use.
docker compose ps: shows the running containers and their ports.docker compose logs -f: follows the live logs. Exit with Ctrl+C.docker compose pull && docker compose up -d: pulls new images and switches containers to the new version.docker compose down: stops and removes the containers. Data in volumes stays as is.
With restart: unless-stopped, containers come back up automatically when the server restarts. Only containers you stopped yourself stay stopped.
Firewall and port exposure settings
Docker opens ports published with ports: by adding firewall rules (iptables) directly. So a port listed under ports: is reachable from outside even if ufw does not allow it. For databases or admin panels that do not need to be visible outside, bind them to 127.0.0.1 as below so they are reachable only from within the server.
ports:
- "127.0.0.1:5432:5432"For web services, publish only ports 80 and 443 and let the rest call each other by service name inside the same Compose network for a clean setup. For the server's overall basic firewall, follow the basic firewall guide and open only SSH, HTTP and HTTPS.
Log and disk management
Unless you set a limit, container logs keep piling up. Set the local log driver in /etc/docker/daemon.json as below, and logs are compressed and kept only up to a set size. After saving, run systemctl restart docker; it applies to containers created from then on.
{
"log-driver": "local"
}Unused images and stopped containers take up disk space too. Check usage with docker system df and clean up images not in use with docker image prune -a. As data grows, you can also attach an NVMe block disk to the server and use it as the Docker data folder.
Protecting your data and next steps
Containers can be deleted and recreated anytime, but the data in volumes cannot be recreated. Keep regular dump files of your databases, and protect the whole server with automatic backups or snapshots for peace of mind. How to do this is in the backups and snapshots guide.
The Compose file for running WordPress with Docker is in the WordPress install guide. If you want to deploy several apps from a dashboard and get HTTPS certificates attached automatically, create a server with the Coolify or Dokploy image. Good sizes for container-only use are listed under Container VPS.
