Skip to content
Hosting Operations8 min read

Running Docker on VPS: 10 Common Questions [2026]

Get answers to the 10 most common Docker on VPS questions: installation, container management, networking, and persistent storage fixes.

Written by Abdul AbrorTechnical Hosting Support Engineer
a close up of a network with wires connected to it
On this page

TL;DR — Key takeaways

  • Install Docker on Ubuntu/Debian VPS with the official repository; avoid snap packages for production workloads.
  • Map container ports using -p host:container syntax; adjust firewall rules separately to allow external traffic.
  • Use named volumes or bind mounts for persistent data; volumes survive container removal and rebuilds.
  • Docker Compose simplifies multi-container apps with a single YAML file and docker compose up command.
  • Run containers with restart policies (--restart unless-stopped) to survive host reboots automatically.

Docker turns a VPS into a flexible container platform. You can run isolated applications, test environments, and production workloads on the same host without dependency conflicts.

Most questions I see in support tickets involve installation steps, port mapping confusion, and data persistence. This FAQ covers those pain points with commands you can copy directly into your terminal.

How do I install Docker on a Linux VPS?

Use the official Docker repository for Ubuntu or Debian. The distribution's default package is often outdated.

First, update your package index and install prerequisites:

Then add Docker's GPG key and repository:

Install Docker Engine and verify the installation:

Add your user to the docker group so you can run commands without sudo:

Log out and back in for the group change to take effect. Test with docker run hello-world.

  • sudo apt update && sudo apt install -y ca-certificates curl gnupg
  • sudo install -m 0755 -d /etc/apt/keyrings
  • curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
  • echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
  • sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
  • docker --version
  • sudo usermod -aG docker $USER

How do I run a container and map ports?

The docker run command starts a container. The -d flag runs it in the background, -p maps ports, and --name gives it a readable identifier.

To run an Nginx web server on port 80:

The syntax is -p host_port:container_port. Nginx listens on port 80 inside the container; the flag makes it accessible on the VPS's port 80.

Check running containers with docker ps. Stop a container with docker stop web. Remove it with docker rm web.

  • docker run -d -p 80:80 --name web nginx:latest

Why can't I reach my container from the outside?

Port mapping is only half the solution. Firewall rules control external access.

If you're using UFW, allow the port explicitly:

Check the rule took effect with sudo ufw status. If you're behind a provider firewall (AWS security groups, DigitalOcean firewall), add an inbound rule there too.

Test locally first. SSH into the VPS and run curl localhost:80. If that works but external requests fail, it's definitely a firewall issue.

  • sudo ufw allow 80/tcp
  • sudo ufw reload

How do I make container data persist?

Containers are stateless by design. When you remove a container, its filesystem disappears.

Named volumes store data outside the container lifecycle. Create one and mount it:

The volume persists even after docker rm postgres. List volumes with docker volume ls. Inspect one with docker volume inspect pgdata.

Bind mounts work too. They map a host directory directly:

Use volumes for databases and application state. Use bind mounts for configuration files you edit frequently.

  • docker volume create pgdata
  • docker run -d -v pgdata:/var/lib/postgresql/data --name postgres postgres:15
  • docker run -d -v /home/user/config:/etc/app/config --name app myapp:latest

What is Docker Compose and when should I use it?

Docker Compose manages multi-container applications with a single YAML file. Instead of running three docker run commands for a web app, database, and cache, you define them once and start everything together.

A minimal docker-compose.yml looks like this:

Start the stack with docker compose up -d. Stop it with docker compose down. The down command removes containers but preserves volumes by default.

Compose is already installed if you used the docker-compose-plugin package. Check with docker compose version.

  • version: '3.8'
  • services:
  • web:
  • image: nginx:latest
  • ports:
  • - "80:80"
  • db:
  • image: postgres:15
  • volumes:
  • - pgdata:/var/lib/postgresql/data
  • environment:
  • POSTGRES_PASSWORD: example
  • volumes:
  • pgdata:

How do I keep containers running after a VPS reboot?

By default, containers stay stopped after the host restarts.

Add a restart policy when creating the container:

The unless-stopped policy restarts the container automatically unless you explicitly stopped it with docker stop. Other options include always (even if you stopped it) and on-failure (only after a non-zero exit).

For existing containers, update the policy without recreating them:

Check the policy with docker inspect web | grep RestartPolicy -A 3.

  • docker run -d --restart unless-stopped -p 80:80 --name web nginx:latest
  • docker update --restart unless-stopped web

How do I check what's using disk space?

Docker accumulates images, stopped containers, unused volumes, and build cache. A VPS with 25GB storage can fill up fast.

See the breakdown:

Remove stopped containers, dangling images, and unused networks:

Remove unused volumes separately (this is destructive):

I've seen VPS instances with 15GB of Docker cache and zero running containers. Run docker system prune weekly or set up a cron job.

  • docker system df
  • docker system prune -a
  • docker volume prune

How do I access a running container's shell?

Use docker exec to run commands inside a running container:

The -it flags give you an interactive terminal. Replace /bin/bash with /bin/sh if the image doesn't include bash.

This is useful for debugging, checking logs in /var/log, or verifying file permissions. Exit with Ctrl+D or type exit.

To see logs without entering the shell, use docker logs web. Add -f to follow logs in real time.

  • docker exec -it web /bin/bash

Can I run Docker without root access?

By default, Docker requires root because it manipulates kernel namespaces and network interfaces.

Adding your user to the docker group lets you run docker commands without sudo, but the Docker daemon still runs as root. This is the standard approach for single-user VPS setups.

Rootless Docker exists for stricter security requirements. It runs the daemon as a non-root user. Installation is more involved and has limitations (no host port binding below 1024 without extra configuration).

For most VPS hosting scenarios, the docker group method is sufficient. Reserve rootless mode for multi-tenant environments or compliance-driven infrastructure.

    What should I back up before upgrading Docker?

    Volumes, container configurations, and Compose files. Images can be re-pulled.

    Back up all volumes:

    Export container configurations if you created containers manually instead of with Compose:

    Copy your docker-compose.yml files and any .env files. Store them outside /var/lib/docker.

    Test the backup by restoring a volume to a new container. I've handled tickets where a failed upgrade nuked volumes because the admin assumed Docker handled backups automatically. It doesn't.

    • docker volume ls -q | xargs -I {} docker run --rm -v {}:/data -v $(pwd):/backup alpine tar czf /backup/{}.tar.gz -C /data .
    • docker inspect web > web-config.json

    Quick reference: common Docker commands

    Here's a table of the commands you'll use most often:

    • docker ps — list running containers
    • docker ps -a — list all containers (including stopped)
    • docker images — list downloaded images
    • docker run -d -p 80:80 --name web nginx — run a container in the background with port mapping
    • docker stop web — stop a running container
    • docker start web — start a stopped container
    • docker rm web — remove a stopped container
    • docker logs web — view container logs
    • docker logs -f web — follow logs in real time
    • docker exec -it web /bin/bash — open a shell inside a running container
    • docker volume create mydata — create a named volume
    • docker volume ls — list volumes
    • docker system df — show disk usage by Docker
    • docker system prune -a — remove unused images, containers, and networks
    • docker compose up -d — start all services defined in docker-compose.yml
    • docker compose down — stop and remove all services

    Quick troubleshooting checklist

    • Install Docker using the official apt repository
    • Add your user to the docker group to run commands without sudo
    • Configure UFW or iptables to allow required container ports
    • Create named volumes for database and application data
    • Set restart policies on production containers
    • Use Docker Compose for multi-container applications
    • Monitor disk usage with docker system df
    • Set up log rotation to prevent disk exhaustion
    • Test container connectivity with docker exec and curl
    • Back up volumes before major changes

    FAQ

    How do I expose a Docker container port to the internet?

    Use the -p flag when running the container: docker run -d -p 80:8080 myapp maps container port 8080 to host port 80. Then configure your firewall (ufw allow 80 or iptables) to permit external traffic. The VPS firewall and any provider-level security groups must also allow the port.

    Why does my container lose data after I restart it?

    Container filesystems are ephemeral by default. Create a named volume (docker volume create mydata) and mount it with -v mydata:/app/data when running the container. Alternatively, use a bind mount with -v /host/path:/container/path to map a host directory. Volumes persist independently of container lifecycle.

    Can I run Docker Compose on a VPS with 1GB RAM?

    Yes, but monitor memory usage closely. A basic stack (web server, small database) typically runs on 1GB. Use docker stats to track consumption in real time. Consider adding swap space (1-2GB) as a buffer. For resource-heavy applications like Elasticsearch or multiple databases, upgrade to 2GB or more.