The Short Answer
Docker turns your VPS into a tidy stack of isolated containers: each application — a website, a database, a game server — runs in its own box with its own dependencies, so nothing conflicts and nothing breaks when you update one service. On Ubuntu 24.04 the reliable way to install it is from Docker’s official APT repository (not the older docker.io package in Ubuntu’s own repos), which takes about ten minutes: add Docker’s GPG key and repository, install docker-ce, docker-ce-cli, containerd.io and the Compose plugin, add your user to the docker group, and verify with docker run hello-world. This guide walks through every step, then shows you how to run a real service with Docker Compose.
Before you start, make sure your server is secured — if you have not done the basics yet, read How to Secure Your VPS first. Docker opens ports on your server, and a container with a weak password is just as exposed as any other service.
What You Need
- A VPS running Ubuntu 24.04 LTS with at least 1 GB of RAM (2 GB is more comfortable if you plan to run several containers).
- A non-root user with sudo access.
- SSH access to the server. If you are on Windows and have not set up SSH keys yet, see How to Use SSH Keys on Windows.
Docker runs on almost every provider’s Ubuntu image, from a cheap $4–$5/month VPS up to a large cloud instance. If you are still choosing a server, Best Cheap VPS Under $5 in 2026 compares the budget options — just make sure the plan has enough RAM for what you intend to containerise.
Step 1: Update the System and Install Prerequisites
Log in to your server and bring the package lists up to date:
sudo apt update
sudo apt upgrade -y
Then install the small set of tools Docker’s repository setup needs:
sudo apt install -y ca-certificates curl
ca-certificates lets APT verify HTTPS connections to Docker’s servers, and curl downloads the signing key. Both are usually already present on a fresh Ubuntu 24.04 image; installing them again is harmless.
Step 2: Add Docker’s Official GPG Key and Repository
Docker signs its packages with a GPG key. Download it into the keyring directory APT reads:
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
Now add the Docker repository to APT’s sources. This command detects your Ubuntu version automatically, so it works on 24.04 (noble) without editing:
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
Refresh the package lists so APT sees the new repository:
sudo apt update
Why the official repository instead of Ubuntu’s docker.io package? The Ubuntu package works, but it lags behind Docker’s releases — sometimes by months — and its Compose support is a separate, older plugin. Docker’s own repository gives you current versions of the engine, the CLI and Compose, all updated together. The ten extra minutes of setup pay for themselves the first time you need a feature that only exists in a newer release.
Step 3: Install Docker Engine and Compose
Install the engine, the command-line client, the container runtime and the Compose plugin in one command:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Here is what each package does:
docker-ce— the Docker daemon, the background service that actually runs containers.docker-ce-cli— thedockercommand you type.containerd.io— the low-level container runtime the daemon uses.docker-buildx-plugin— builds images, including multi-architecture builds.docker-compose-plugin— thedocker composecommand (note the space, not a hyphen) for running multi-container applications from a YAML file.
When the install finishes, Docker starts automatically. Check that the service is running:
sudo systemctl status docker --no-pager
You should see active (running). If the service is not running, start and enable it explicitly:
sudo systemctl enable --now docker
Step 4: Run Docker Without sudo (Optional but Recommended)
By default only root and members of the docker group can talk to the Docker daemon. Typing sudo before every Docker command gets old fast, so add your user to the group:
sudo usermod -aG docker $USER
Then log out and log back in (or run newgrp docker in the current shell) for the group change to take effect. Verify it worked:
docker run hello-world
This downloads a tiny test image and runs it. If you see “Hello from Docker!” followed by a short explanation, your installation works. If you get a permission error, you are probably still in the old shell session — log out and back in again.
The docker group is effectively root access. Anyone who can run Docker commands can mount the host’s entire filesystem into a container (docker run -v /:/host ...) and read or change anything. Only add users you trust completely, and never add a service account that runs untrusted code.
Step 5: Verify the Installation
Confirm the versions you installed:
docker --version
docker compose version
You should see Docker Engine in the 27.x or 28.x range and Compose v2 (for example, Docker Compose version v2.x.x). Exact numbers change with releases — what matters is that both commands respond without errors.
Also check that containers survive a reboot. Docker is enabled as a systemd service by default, so the daemon restarts with the server. Containers themselves restart only if you set a restart policy — see Step 7.
Step 6: Run Your First Real Container
The hello-world image proves Docker works; a web server proves it is useful. Run Nginx in a container, mapping port 8080 on the host to port 80 in the container:
docker run -d --name webtest -p 8080:80 nginx:alpine
The flags: -d runs it detached (in the background), --name gives it a memorable name, and -p 8080:80 forwards host port 8080 to container port 80. Check it is running:
docker ps
Then open http://YOUR_SERVER_IP:8080 in a browser — you should see the Nginx welcome page. If your firewall is enabled, allow the port first:
sudo ufw allow 8080/tcp
Stop and remove the test container when you are done:
docker stop webtest
docker rm webtest
Step 7: Manage Containers with Docker Compose
Running one container with docker run is fine. Running a real application — a website plus a database plus a cache — needs Docker Compose, which describes the whole stack in one YAML file. Here is a practical example: WordPress with a MySQL database, the same stack many readers install directly on the VPS (see How to Install WordPress on a VPS for the non-Docker route).
Create a project directory and a compose.yml file:
mkdir -p ~/wordpress && cd ~/wordpress
nano compose.yml
Paste this configuration:
services:
db:
image: mysql:8.4
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: change-this-root-password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: change-this-db-password
volumes:
- db_data:/var/lib/mysql
wordpress:
image: wordpress:latest
restart: unless-stopped
depends_on:
- db
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: change-this-db-password
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
volumes:
db_data:
wp_data:
Replace both passwords with strong, unique values. Then start the stack:
docker compose up -d
Compose pulls the images, creates the containers and the named volumes, and starts everything in the right order. Visit http://YOUR_SERVER_IP:8080 and you will see the WordPress setup screen.
The useful day-to-day commands:
docker compose ps # show running services
docker compose logs -f # follow the logs of all services
docker compose down # stop and remove containers (volumes stay)
docker compose pull # download newer images
docker compose up -d # recreate containers with new images
restart: unless-stopped is the key line for a server: it makes Docker restart your containers after a reboot or a crash, but respects a deliberate docker compose down. Without a restart policy, a 3 a.m. reboot leaves your site offline until you notice.
Keeping Docker Healthy
Disk space. Docker images, stopped containers and unused volumes quietly eat disk. Check usage with docker system df, and clean up unused objects (safe — it only removes things no container uses) with:
docker system prune -a --volumes
Run that with care: --volumes deletes named volumes not attached to a container, which is where databases live. Only use it when you are sure the orphaned volumes are expendable.
Log growth. By default, Docker keeps container logs forever, and a chatty application can fill a small disk. Limit log size in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Then restart Docker with sudo systemctl restart docker. Each container keeps at most three 10 MB log files.
Updates. Docker updates through APT like everything else: sudo apt update && sudo apt upgrade -y covers the engine. Images do not update themselves — run docker compose pull && docker compose up -d periodically for each project, or set up a tool such as Watchtower if you want automatic image updates (understand the risk first: an automatic update can restart a service at an awkward moment).
Troubleshooting
“permission denied while trying to connect to the Docker daemon socket.” Your user is not in the docker group yet, or you have not logged out and back in since adding it. Run groups to check — docker should be listed. If it is not, repeat Step 4 and start a fresh SSH session.
“docker: command not found.” The install did not complete, or APT did not pick up the repository. Re-run sudo apt update and look for errors about the Docker repository — a failed GPG key download is the usual cause. Re-download the key (Step 2) and try again.
“Cannot connect to the Docker daemon.” The daemon is not running. Check sudo systemctl status docker and start it with sudo systemctl start docker. If it fails to start, sudo journalctl -u docker -n 50 shows the error — a common cause is a malformed /etc/docker/daemon.json (JSON syntax error).
“port is already allocated.” Two containers (or a host service) want the same host port. Find the occupant with sudo ss -tlnp | grep PORT or docker ps, then change the host-side port in your -p or Compose mapping — the container side can stay the same.
Containers work but the site is unreachable. Three usual suspects: the firewall (sudo ufw allow PORT/tcp), the provider’s cloud firewall (DigitalOcean, Vultr and others have a separate firewall in the control panel), and binding the port to the wrong interface. Also confirm the container is actually listening: docker logs CONTAINER_NAME often reveals an application crash.
“no space left on device” inside a container. The host disk is full, or Docker’s storage driver has run out of room. Check df -h on the host and docker system df for Docker’s own usage, then prune unused images and volumes.
Frequently Asked Questions
How much RAM does Docker need on a VPS?
Docker itself uses very little — roughly 100–200 MB for the daemon. What matters is the containers you run: a WordPress + MySQL stack wants at least 1 GB free, and each additional service adds its own footprint. On a 1 GB VPS, run one small stack; on 2 GB or more you have room to grow. If the server feels tight, see How to Speed Up Your VPS and How to Upgrade Your VPS.
Should I use Docker or install software directly on the VPS?
Both are valid. Docker wins when you run several applications with conflicting dependencies, want identical environments across servers, or like clean uninstalls (delete the container and it is gone). Direct installation wins when you want maximum performance on a tiny server, or when the software is a single well-behaved service such as Nginx. Many experienced operators mix the two: the web server directly on the host, everything else in containers.
Is Docker Compose the same as docker-compose?
Almost. docker compose (with a space) is Compose v2, distributed as a Docker plugin and the current standard. docker-compose (with a hyphen) is the older standalone v1 binary, now deprecated. Use docker compose — the v1 binary is no longer maintained.
Do containers start automatically after a reboot?
Only if they have a restart policy. Set restart: unless-stopped in Compose, or --restart unless-stopped with docker run. Without it, containers stay stopped after a reboot and you must start them manually with docker start or docker compose up -d.
Can I run Docker on a free-tier VPS?
Yes, if the server has enough RAM. The Oracle Cloud Always Free Ampere instance (2 OCPUs / 12 GB RAM, ARM) runs Docker well, though you need ARM-compatible images — most official images support ARM64, but check before relying on a niche image. Tiny 512 MB or 1 GB instances can run Docker, but only for one or two lightweight containers. See Best Free VPS in 2026 for the current free options.
How do I update a container to a newer version?
Pull the new image and recreate the container: docker compose pull && docker compose up -d for Compose projects, or docker pull IMAGE followed by stopping, removing and re-running the container for standalone ones. Named volumes keep your data across recreations — that is why the WordPress example above stores the database in db_data rather than inside the container.
The Bottom Line
Install Docker from its official repository, add your user to the docker group, and manage real applications with Compose files that include a restart policy and named volumes. Ten minutes of setup gives you isolated, reproducible, easily updated services on any Ubuntu 24.04 VPS — and a clean way to run a website, a database and a cache side by side without dependency conflicts.



Leave a Reply