Docker container and shipping

Docker Basics on VPS for Beginners

June 2026 · 7 min read

Docker has completely changed how developers run software on servers. Instead of installing software directly on the OS, you run it in isolated containers separate from the system. This article explains what Docker is and how to use it on a VPS.


What is Docker and How Does It Differ from VMs

A VM (Virtual Machine) simulates entire hardware including the OS, making it heavy and slow to boot. Docker uses only the OS kernel of the host and isolates just the process, making it much lighter and faster to start—within seconds.

Installing Docker on Ubuntu/Debian

curl -fsSL https://get.docker.com | sh
usermod -aG docker $USER   # Add user to docker group to run docker without sudo
newgrp docker

Verify the installation:

docker run hello-world

Basic Docker Commands

# Run a container from an image
docker run -d -p 80:80 nginx

# List running containers
docker ps

# View logs from a container
docker logs container_id

# Stop a container
docker stop container_id

# Remove a container
docker rm container_id

# List available images
docker images

# Remove an image
docker rmi image_name

Docker Compose: Run Multiple Containers Together

Most applications need multiple services running simultaneously, such as a web server + database + cache. Docker Compose helps manage this with a single file.

Example docker-compose.yml for WordPress:

services:
  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: wordpress
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:latest
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: rootpass
    depends_on:
      - db

volumes:
  db_data:
docker compose up -d   # Run all services in the background
docker compose down    # Stop and remove all containers

Volumes: Persist Data So It Doesn't Get Lost When Containers Are Removed

Data inside a container is lost immediately when the container is deleted. You need to mount a volume to persist data permanently:

# Mount a directory from the host
docker run -v /host/path:/container/path nginx

# Use a named volume (Docker manages it)
docker run -v mydata:/app/data nginx

Important Considerations on a VPS


Summary

Docker makes deploying applications on a VPS much easier and reproducible. The environment you run on your local machine will work the same way on a production server. Install Docker and try running Nginx or WordPress with Compose to see how it works right away.

Verify Docker is Working Correctly

# Check Docker daemon status
systemctl status docker

# List running containers
docker ps

# View resource usage of all containers
docker stats --no-stream

# Check disk space used by Docker
docker system df
Clean Up Docker: Run docker system prune regularly to delete unused containers, networks, and images. This prevents your disk from filling up with unused Docker layers.

Common Issues & Troubleshooting

Error: "Got permission denied while trying to connect to Docker daemon"

The user is not yet in the docker group:

# Add user to docker group
usermod -aG docker $USER

# Log out and log back in, or run
newgrp docker

# Test
docker ps

Error: "port is already allocated" when running docker run

The port is already in use by another service:

# Check which port is in use
ss -tlnp | grep :80
# or
lsof -i :80

# Stop the conflicting service
systemctl stop nginx
# or map Docker to a different port
docker run -p 8080:80 nginx   # Use port 8080 instead

Container restart loop — status "Restarting"

# View logs from the crashed container
docker logs container_name --tail=50
docker logs container_name --since 5m

# Check the exit code
docker inspect container_name | grep ExitCode

Docker compose gives error "yaml: line X: did not find expected key"

YAML indentation is wrong. Use spaces instead of tabs:

# Check yaml syntax
docker compose config
# If valid, it will display the parsed configuration

Container logs are filling up the disk

Set a log limit in docker-compose.yml:

services:
  myapp:
    image: myapp:latest
    logging:
      driver: json-file
      options:
        max-size: "10m"
        max-file: "3"

Frequently Asked Questions

How much extra RAM does Docker need?

The Docker daemon itself uses about 100–200 MB of RAM. Each container depends on the app running inside it. For example, an Nginx container uses 10–30 MB, while MySQL uses 200–500 MB. You should keep at least 500 MB of free RAM available.

Can I use Docker on a low-spec VPS?

Yes. Docker is much lighter than VMs. However, if multiple containers run simultaneously, their RAM usage adds up. A 1 GB RAM VPS can comfortably run 2–3 small containers. If you run a database + web server + cache together, you'll want 2 GB+ of RAM.

Will data in Docker volumes disappear if I update the image?

No. Volumes are separate from the container lifecycle. Running docker compose pull and then up -d will recreate containers, but mounted volumes will persist completely.