GuidesDocker on Your VPS

Docker on Your VPS

Install Docker and run containerised applications easily.

Install Docker

bash
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker
# Add your user to docker group (no sudo needed)
usermod -aG docker $USER

Basic Docker Commands

bash
docker pull nginx           # Download an image
docker run -d -p 80:80 nginx  # Run a container
docker ps                   # List running containers
docker ps -a                # List all containers
docker stop container_id    # Stop a container
docker rm container_id      # Remove a container
docker images               # List downloaded images
docker logs container_id    # View container logs

Docker Compose

Compose lets you define multi-container apps in a single YAML file:

bash
apt install -y docker-compose-plugin
docker-compose.yml
version: '3.8'
services:
  app:
    image: node:20-alpine
    ports:
      - "3000:3000"
    volumes:
      - ./app:/app
    working_dir: /app
    command: node server.js
    restart: unless-stopped

  db:
    image: mariadb:11
    environment:
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_DATABASE: myapp
    volumes:
      - db_data:/var/lib/mysql
    restart: unless-stopped

volumes:
  db_data:
bash
docker compose up -d     # Start in background
docker compose logs -f   # Watch logs
docker compose down      # Stop everything
Add restart: unless-stopped so containers start automatically after a server reboot.