A Docker VPS is a Linux virtual server on which you install Docker Engine and run your applications as containers, usually defined in a Docker Compose file. A cloud VPS with 2 vCPU and 2 to 4 GB of RAM is enough for a handful of small services. The parts that go wrong are not the install but the defaults: published ports that bypass the firewall, logs that fill the disk, containers with no memory limit and volumes nobody has backed up. This guide covers each of them on Ubuntu 22.04 or 24.04.
Prepare the server first. If it is brand new, follow the first 30 minutes of VPS setup (non-root user, SSH keys, firewall, updates) and come back here.
When a Docker VPS makes sense
Containers package an application with its dependencies, so the same image runs on your laptop and on the server. On a VPS this helps when:
- You run several apps on one server. Each gets its own Node, Python or PHP version without clashing on the host.
- You deploy often. Updating becomes pulling a new image tag and restarting, and rolling back is changing the tag back.
- You use software that ships as a Docker image, such as n8n, databases, Redis or monitoring tools.
It is less useful for a single static site or a simple PHP app, where a plain Nginx and PHP setup has fewer moving parts. Containers also add a layer you must understand when debugging, and you remain responsible for patching both the host and the images.
Check that your VPS can run Docker
Docker needs kernel features such as namespaces, cgroups and iptables. A KVM-based VPS has its own kernel and runs Docker normally. Some container-based plans (for example LXC or OpenVZ) restrict these features. Check what you have before installing:
systemd-detect-virt
uname -r
nproc; free -h; df -h /
A result of kvm is what you want. If you are unsure what your plan runs on, our KVM VPS guide explains how to verify it.
Step 1: Install Docker Engine and the Compose plugin
Use Docker's official apt repository rather than the older docker.io package from the Ubuntu archive. The current, exact commands are on docs.docker.com, and they change between releases, so copy them from there. In outline you remove conflicting packages, add Docker's signing key and repository, then install:
sudo apt-get install docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin
Confirm that the service runs at boot and that a test container works:
sudo systemctl enable --now docker
docker --version
docker compose version
sudo docker run --rm hello-world
Note the command is docker compose (with a space), part of the plugin. The older standalone docker-compose binary is no longer the recommended route.
Step 2: Run Docker without root, but understand the risk
To avoid typing sudo for every command, add your admin user to the docker group:
sudo usermod -aG docker $USER
# log out and back in, then:
docker ps
Be clear about what this does. Anyone in the docker group can start a container that mounts the host filesystem, which is effectively root access. Add only trusted administrators, never application users. Docker also has a rootless mode (see the official documentation) that limits this, at the cost of some restrictions such as binding to ports below 1024.
Inside containers, avoid running the application as root where the image allows it. Many images support a user: setting or a non-root user, and a container that runs as an unprivileged user limits the damage if the application is compromised.
Step 3: Write a Compose file with sensible defaults
Keep each project in its own directory, with a docker-compose.yml and a .env file for secrets. A small example with a web app and Redis:
services:
app:
image: myorg/myapp:1.4.2
restart: unless-stopped
env_file: .env
ports:
- "127.0.0.1:3000:3000"
depends_on:
- redis
mem_limit: 512m
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
redis:
image: redis:7-alpine
restart: unless-stopped
command: ["redis-server", "--appendonly", "yes"]
volumes:
- redis-data:/data
mem_limit: 256m
volumes:
redis-data:
What each choice is for:
- Pinned image tags.
1.4.2instead oflatestmeans an update happens when you decide, not when the registry changes. restart: unless-stoppedbrings containers back after a crash or a server reboot.127.0.0.1:3000:3000publishes the port to the server itself only. A reverse proxy (see below) exposes it to the internet. Redis has noportsentry at all, so only other containers in the same Compose network can reach it.mem_limitstops one container from consuming all RAM and triggering the kernel out-of-memory killer on the host. Set it from observed usage.- Log options cap each container's log at 3 files of 10 MB.
- Named volumes keep data outside the container, so recreating the container does not delete it.
Start and inspect it:
docker compose up -d
docker compose ps
docker compose logs --tail 50 app
docker stats --no-stream
Docker and ufw: the firewall trap
This is the most common Docker security mistake on a VPS. Docker writes its own iptables rules for published ports. A port published as "3000:3000" (no 127.0.0.1) can be reachable from the internet even if ufw says it is denied, because Docker's rules are evaluated before ufw's. A database published as "5432:5432" or "6379:6379" is then open to the world.
Practical rules:
- Publish to
127.0.0.1unless a service genuinely must be public. - Do not publish database and cache ports at all. Let containers talk over the Compose network.
- Check from outside, not from the server:
nmap -p 1-10000 YOUR_SERVER_IPfrom another machine, or list listeners withsudo ss -tlnp. - If you need a host-level rule that Docker respects, Docker documents the
DOCKER-USERiptables chain for that purpose. Read the current documentation before using it. - Also use the network firewall or security group of your hosting plan if one is available, since it sits outside the server.
Step 4: Put Nginx in front for HTTPS
For websites and APIs, run Nginx on the host (or as a container) as a reverse proxy, with a free Let's Encrypt certificate from Certbot. The application stays bound to 127.0.0.1 and Nginx forwards to it:
server {
listen 80;
server_name app.example.in;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Then run sudo certbot --nginx -d app.example.in to add HTTPS and automatic renewal. The full host setup, including firewall rules for ports 80 and 443, is in our guide to deploying Nginx, PHP and Node with HTTPS. WebSocket applications need extra Upgrade headers, which the application's documentation usually lists.
Keep the disk and memory under control
Docker is a common reason a VPS disk fills up. Images, stopped containers, build cache and logs accumulate silently.
- Look first:
docker system dfanddf -h. - Clean unused data:
docker image pruneremoves dangling images.docker system pruneremoves more (stopped containers, unused networks); read the confirmation prompt, and never add--volumesunless you are sure, because that deletes unused volumes with data in them. - Set a default log limit for every container in
/etc/docker/daemon.json, then restart Docker:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}
The daemon default applies to containers created after the change, so recreate existing ones with docker compose up -d --force-recreate. For memory, add a small swap file as a safety net and watch docker stats. Constant swapping means the plan is too small, and resizing is better than tuning. Routine checks like these belong in the monthly Linux VPS checklist.
Back up volumes and Compose files
Containers are disposable. Your data is not. Back up three things: the Compose files and .env (in Git or a protected copy), the named volumes or bind-mounted directories, and database dumps taken with the database's own tool. A database directory copied while the database runs can be inconsistent, so dump it instead:
docker compose exec -T db pg_dump -U appuser appdb | gzip > /backup/appdb-$(date +%F).sql.gz
# a named volume to a tar file
docker run --rm -v redis-data:/data -v /backup:/backup alpine \
tar czf /backup/redis-data-$(date +%F).tar.gz -C /data .
Copy the files off the server, since a backup on the same disk does not survive losing the disk. A provider snapshot of the whole VPS is a useful second layer. See the cloud server backup guide for snapshots, offsite copies and restore tests, and actually test restoring into a fresh container.
Updating containers
- Read the release notes for the new image version.
- Take a database dump and, for larger changes, a VPS snapshot.
- Change the tag in the Compose file, then run
docker compose pullanddocker compose up -d. - Check
docker compose logsand the application itself. - To roll back, restore the data if needed and put the previous tag back.
Remember that updating containers does not patch the host. Keep Ubuntu itself updated with apt and unattended security updates, and reboot when a kernel update requires it.
India-specific points
- Personal data. If your containers process personal data of customers or employees, India's Digital Personal Data Protection Act, 2023 applies to how you protect and delete it. Container logs and database volumes both count as places where such data can sit. See MeitY for the official text and our article on why businesses are moving hosting back to India.
- Latency. A server in Delhi is close to many Indian users and to Indian APIs such as payment, GST and logistics services. Measure with
curl -wfrom the server rather than assuming. - Image pulls. Large images pulled from foreign registries use bandwidth and time. Keep images small (alpine or slim variants) and use multi-stage builds.
- Billing. INR billing with a GST invoice is simpler to book than a dollar card charge.
How AvertHost can help
AvertHost provides managed Linux and Windows cloud VPS from a Tier-IV data centre in Delhi, with a 99.9% uptime SLA, INR billing with GST invoices and 24/7 support. A Linux cloud VPS running Ubuntu is the base for the setup in this article. We provide the server and the platform. Installing and updating Docker, your images and your applications is your responsibility unless you agree otherwise with the support team in writing. Check the plan page for current specifications and prices before sizing, and see all cloud services if you need other options.
FAQ
How much RAM does a Docker VPS need?
Docker itself uses little. What matters is your containers. As a starting point (RECOMMENDATION, not a benchmark), 2 GB RAM runs a few small services, and 4 GB is more comfortable once a database such as PostgreSQL runs on the same server. Measure with docker stats and set memory limits from real usage.
Can I run Docker on any VPS?
Not always. A KVM-based VPS with its own kernel runs Docker normally, while some container-based VPS types restrict the features it needs. Run systemd-detect-virt and ask the provider if the result is not kvm.
Why is my container port open even though ufw blocks it?
Docker adds its own iptables rules for published ports, and they are processed before ufw. Bind the port to 127.0.0.1 in Compose, or do not publish it, and verify with a scan from another machine.
Is Docker Compose enough for production?
For a single VPS with a few services, yes, if you pin image versions, set restart policies, limit logs and memory, and back up volumes. If you need many servers, automatic failover or rolling updates across nodes, look at an orchestrator such as Kubernetes, which is a larger operational commitment.
How do I stop Docker filling my disk?
Set log rotation in daemon.json or per service, run docker image prune regularly, and check docker system df. Avoid docker system prune --volumes unless you know which volumes are unused.