How to Install and Use Docker on a VDS: Beginner Guide

How to Install and Use Docker on a VDS: Beginner Guide

Install Docker on a Linux VDS, run your first containers, orchestrate services with Docker Compose and deploy a web app, step by step.

White Bilişim

Installing and Using Docker on a VDS

Docker lets you run applications in isolated containers, which makes deploying web apps, databases and microservices on a single server far less painful. This guide covers installing Docker on a Linux VDS and the commands you will use every day.

What Is Docker?

Docker runs your applications inside containers: lightweight, portable, self contained environments. Containers use a fraction of the resources a virtual machine needs and start in seconds rather than minutes.

FeatureVirtual MachineDocker Container
Startup timeMinutesSeconds
Resource overheadHighLow
IsolationFull OS isolationApplication level
SizeGigabytesMegabytes
PortabilityLowHigh

💡 Docker makes efficient use of your VDS resources by letting one server host several applications. Xeon Enterprise VDS plans are a good fit for container workloads.

Step 1: Install Docker (Ubuntu and Debian)

# Remove older versions
sudo apt remove docker docker-engine docker.io containerd runc 2>/dev/null
 
# Install the required dependencies
sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release -y
 
# Add the Docker GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
 
# Add the Docker repository
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 > /dev/null
 
# Install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
 
# Verify the installation
sudo docker run hello-world

Running Docker Without Root

# Add your user to the docker group
sudo usermod -aG docker $USER
 
# Activate the group (or log out and back in)
newgrp docker

Step 2: The Commands You Will Actually Use

Managing Containers

# Run a container
docker run -d --name webserver -p 80:80 nginx
 
# List running containers
docker ps
 
# List all containers
docker ps -a
 
# Stop a container
docker stop webserver
 
# Start a container
docker start webserver
 
# Remove a container
docker rm webserver
 
# View container logs
docker logs webserver
 
# Open a shell inside a container
docker exec -it webserver bash

Managing Images

# Pull an image
docker pull nginx:latest
 
# List local images
docker images
 
# Remove an image
docker rmi nginx:latest
 
# Clean up unused images
docker image prune -a

Step 3: Multiple Services With Docker Compose

Docker Compose lets you define and manage a whole stack from a single file.

Example: WordPress and MariaDB

# docker-compose.yml
version: '3.8'
 
services:
  wordpress:
    image: wordpress:latest
    restart: always
    ports:
      - "80:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wpuser
      WORDPRESS_DB_PASSWORD: strong_password_123
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - wp_data:/var/www/html
 
  db:
    image: mariadb:latest
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wpuser
      MYSQL_PASSWORD: strong_password_123
      MYSQL_ROOT_PASSWORD: root_password_456
    volumes:
      - db_data:/var/lib/mysql
 
volumes:
  wp_data:
  db_data:
# Start the services
docker compose up -d
 
# Check the status
docker compose ps
 
# Follow the logs
docker compose logs -f
 
# Stop the services
docker compose down

Step 4: Building Your Own Image

A Dockerfile for a Node.js App

# Dockerfile
FROM node:20-alpine
 
WORKDIR /app
 
COPY package*.json ./
RUN npm ci --production
 
COPY . .
 
EXPOSE 3000
 
CMD ["node", "server.js"]
# Build the image
docker build -t my-app:latest .
 
# Run it as a container
docker run -d --name my-app -p 3000:3000 my-app:latest

Docker Security

Baseline Practices

  1. Do not run containers as root: use the USER directive
  2. Prefer official images: verified publishers on Docker Hub
  3. Keep images current: rebuild and pull regularly
  4. Isolate networks: separate containers that do not need to talk
  5. Set resource limits: cap CPU and memory per container
# Run a container with resource limits
docker run -d --name app \
  --memory=512m \
  --cpus=1 \
  -p 8080:80 \
  nginx

Which Plan for Docker Workloads

Use caseRecommended planSpecs
1 to 3 containersENT-22 Core, 4 GB RAM, 240 TRY per month
5 to 10 containersENT-46 Core, 8 GB RAM, 400 TRY per month
Microservice stackPRO-36 Core Ryzen, 8 GB RAM, 800 TRY per month
Large infrastructurePRO-612 Core Ryzen, 16 GB RAM, 1,600 TRY per month

Conclusion

Docker is the most practical way to run several isolated applications on one VDS, and it keeps your infrastructure costs down by consolidating workloads onto fewer machines.

👉 See Xeon Enterprise VDS for container workloads, or Ryzen Premium VDS for a heavier microservice stack. Running a bot inside a container? The Discord bot VDS and Telegram bot VDS pages cover sizing.