🐳 Install Docker on a Linux VPS

Complete guide to install Docker and Docker Compose on your Linux VPS. Docker allows you to create, deploy and run applications in isolated containers.

🐳 Install Docker on a Linux VPS

This guide explains how to install Docker and Docker Compose on your Linux VPS. Docker is a containerization platform that allows you to create, deploy and run applications in isolated containers, making application deployment and management easier.

📋 Prerequisites

  • A Linux VPS with root or sudo access
  • Ubuntu 20.04+ or Debian 11+ (or CentOS 7+/RHEL 7+)
  • At least 1 GB of RAM (2 GB recommended)
  • A stable Internet connection

💡 Infrastructure Recommendation

Docker requires fast disks for compilation and intensive I/O operations. We recommend our NVMe VPS for optimal performance when using Docker. NVMe drives offer speeds up to 10x faster than traditional SSDs, significantly accelerating Docker image builds and container startup times.

⚠️ Important before installation

  • Check your system : Docker requires a 64-bit system
  • Backup your data : Installation may modify some system configurations
  • Installation time : Installation typically takes 5 to 10 minutes

🔧 Installation on Ubuntu/Debian

Step 1: Update the system

# Update package list sudo apt update # Update installed packages sudo apt upgrade -y

Step 2: Install dependencies

# Install necessary packages sudo apt install -y \ ca-certificates \ curl \ gnupg \ lsb-release

Step 3: Add Docker's official GPG key

# Create directory for keys sudo install -m 0755 -d /etc/apt/keyrings # Download and add GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg # Set correct permissions sudo chmod a+r /etc/apt/keyrings/docker.gpg

Step 4: Configure Docker repository

# Add 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

Step 5: Install Docker Engine

# Update package list sudo apt update # Install Docker Engine, containerd and Docker Compose sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 6: Verify installation

# Verify Docker is installed correctly sudo docker --version # Verify Docker Compose is installed sudo docker compose version

🔧 Installation on CentOS/RHEL

Step 1: Update the system

# Update packages sudo yum update -y

Step 2: Install dependencies

# Install necessary packages sudo yum install -y yum-utils

Step 3: Add Docker repository

# Add Docker repository sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Step 4: Install Docker Engine

# Install Docker Engine, containerd and Docker Compose sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 5: Start Docker

# Start Docker service sudo systemctl start docker # Enable Docker on boot sudo systemctl enable docker

Step 6: Verify installation

# Verify Docker is installed correctly sudo docker --version # Verify Docker Compose is installed sudo docker compose version

👤 Step 7: Configure permissions (Important)

By default, Docker requires root privileges. To run Docker without sudo, add your user to the docker group:

# Add your user to docker group sudo usermod -aG docker $USER # Apply changes (logout/login required) newgrp docker

Important : After adding your user to the docker group, you must log out and log back in for changes to take effect.

Verify permissions

# Test Docker without sudo docker run hello-world

If this command works without error, Docker is correctly configured!

🧪 Step 8: Test Docker

Run a test container

# Run Hello World container docker run hello-world

This command will:

  1. Download the hello-world image from Docker Hub
  2. Create a container from this image
  3. Run the container
  4. Display a confirmation message

Check containers

# List running containers docker ps # List all containers (including stopped) docker ps -a # List Docker images docker images

🐙 Step 9: Install Docker Compose (if not included)

If Docker Compose was not installed with Docker Engine, install it separately:

On Ubuntu/Debian

# Download Docker Compose sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # Make executable sudo chmod +x /usr/local/bin/docker-compose # Verify installation docker-compose --version

On CentOS/RHEL

# Download Docker Compose sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose # Make executable sudo chmod +x /usr/local/bin/docker-compose # Verify installation docker-compose --version

📦 Essential Docker commands

Image management

# Download an image docker pull image-name:tag # List images docker images # Remove an image docker rmi image-name # Clean unused images docker image prune -a

Container management

# Create and start a container docker run image-name # Create a container in background (detached) docker run -d image-name # List running containers docker ps # Stop a container docker stop container-id # Start a stopped container docker start container-id # Restart a container docker restart container-id # Remove a container docker rm container-id # View container logs docker logs container-id # Execute a command in a running container docker exec -it container-id /bin/bash

Docker Compose

# Start services defined in docker-compose.yml docker compose up # Start in background docker compose up -d # Stop services docker compose down # View logs docker compose logs # Rebuild images docker compose build

🔒 Securing Docker

Configure Docker daemon (optional)

Create or modify /etc/docker/daemon.json:

sudo nano /etc/docker/daemon.json

Add the following configuration:

{ "log-driver": "json-file", "log-opts": { "max-size": "10m", "max-file": "3" } }

Restart Docker:

sudo systemctl restart docker

Limit Docker access

By default, users in the docker group have root-equivalent privileges. For more security, you can:

  1. Only give access to trusted users
  2. Use Docker rootless (advanced installation)
  3. Configure security policies via AppArmor or SELinux

🔄 Update Docker

On Ubuntu/Debian

# Update packages sudo apt update # Update Docker sudo apt upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

On CentOS/RHEL

# Update Docker sudo yum update docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

🗑️ Uninstall Docker

If you want to uninstall Docker:

On Ubuntu/Debian

# Stop Docker sudo systemctl stop docker # Uninstall packages sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras # Remove images, containers and volumes sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd

On CentOS/RHEL

# Stop Docker sudo systemctl stop docker # Uninstall packages sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras # Remove images, containers and volumes sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd

❓ Common Issues

Error "Cannot connect to the Docker daemon"

Solution:

# Check Docker service is started sudo systemctl status docker # Start Docker if necessary sudo systemctl start docker # Check you are in docker group groups

Error "Permission denied"

Solution:

# Add your user to docker group sudo usermod -aG docker $USER # Log out and log back in

Docker is slow

Possible solutions:

  • Check disk space: df -h
  • Clean unused images: docker system prune -a
  • Check available RAM: free -h

📝 Example: Deploy a simple application

Create a docker-compose.yml file

# Create a directory for your project mkdir my-project cd my-project # Create docker-compose.yml file nano docker-compose.yml

Example content:

version: '3.8' services: web: image: nginx:latest ports: - "80:80" volumes: - ./html:/usr/share/nginx/html restart: unless-stopped

Start the application

# Start services docker compose up -d # Verify container is running docker ps

📞 Need Help?

If you encounter difficulties installing Docker, please contact Infrawire support. Our team is available to help you.


Note : Docker is a powerful tool that greatly simplifies application deployment. Take time to understand the basic concepts before deploying applications in production.