English

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

Bash
1# Update package list 2sudo apt update 3 4# Update installed packages 5sudo apt upgrade -y

Step 2: Install dependencies

Bash
1# Install necessary packages 2sudo apt install -y \ 3 ca-certificates \ 4 curl \ 5 gnupg \ 6 lsb-release

Step 3: Add Docker's official GPG key

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

Step 4: Configure Docker repository

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

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

Step 6: Verify installation

Bash
1# Verify Docker is installed correctly 2sudo docker --version 3 4# Verify Docker Compose is installed 5sudo docker compose version

🔧 Installation on CentOS/RHEL

Step 1: Update the system

Bash
# Update packages sudo yum update -y

Step 2: Install dependencies

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

Step 3: Add Docker repository

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

Step 4: Install Docker Engine

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

Bash
1# Start Docker service 2sudo systemctl start docker 3 4# Enable Docker on boot 5sudo systemctl enable docker

Step 6: Verify installation

Bash
1# Verify Docker is installed correctly 2sudo docker --version 3 4# Verify Docker Compose is installed 5sudo 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:

Bash
1# Add your user to docker group 2sudo usermod -aG docker $USER 3 4# Apply changes (logout/login required) 5newgrp 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

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

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

Bash
1# List running containers 2docker ps 3 4# List all containers (including stopped) 5docker ps -a 6 7# List Docker images 8docker images

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

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

On Ubuntu/Debian

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

On CentOS/RHEL

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

📦 Essential Docker commands

Image management

Bash
1# Download an image 2docker pull image-name:tag 3 4# List images 5docker images 6 7# Remove an image 8docker rmi image-name 9 10# Clean unused images 11docker image prune -a

Container management

Bash
1# Create and start a container 2docker run image-name 3 4# Create a container in background (detached) 5docker run -d image-name 6 7# List running containers 8docker ps 9 10# Stop a container 11docker stop container-id 12 13# Start a stopped container 14docker start container-id 15 16# Restart a container 17docker restart container-id 18 19# Remove a container 20docker rm container-id 21 22# View container logs 23docker logs container-id 24 25# Execute a command in a running container 26docker exec -it container-id /bin/bash

Docker Compose

Bash
1# Start services defined in docker-compose.yml 2docker compose up 3 4# Start in background 5docker compose up -d 6 7# Stop services 8docker compose down 9 10# View logs 11docker compose logs 12 13# Rebuild images 14docker compose build

🔒 Securing Docker

Configure Docker daemon (optional)

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

Bash
sudo nano /etc/docker/daemon.json

Add the following configuration:

JSON
1{ 2 "log-driver": "json-file", 3 "log-opts": { 4 "max-size": "10m", 5 "max-file": "3" 6 } 7}

Restart Docker:

Bash
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

Bash
1# Update packages 2sudo apt update 3 4# Update Docker 5sudo apt upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

On CentOS/RHEL

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

Bash
1# Stop Docker 2sudo systemctl stop docker 3 4# Uninstall packages 5sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras 6 7# Remove images, containers and volumes 8sudo rm -rf /var/lib/docker 9sudo rm -rf /var/lib/containerd

On CentOS/RHEL

Bash
1# Stop Docker 2sudo systemctl stop docker 3 4# Uninstall packages 5sudo yum remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras 6 7# Remove images, containers and volumes 8sudo rm -rf /var/lib/docker 9sudo rm -rf /var/lib/containerd

❓ Common Issues

Error "Cannot connect to the Docker daemon"

Solution:

Bash
1# Check Docker service is started 2sudo systemctl status docker 3 4# Start Docker if necessary 5sudo systemctl start docker 6 7# Check you are in docker group 8groups

Error "Permission denied"

Solution:

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

Bash
1# Create a directory for your project 2mkdir my-project 3cd my-project 4 5# Create docker-compose.yml file 6nano docker-compose.yml

Example content:

YAML
1version: '3.8' 2 3services: 4 web: 5 image: nginx:latest 6 ports: 7 - "80:80" 8 volumes: 9 - ./html:/usr/share/nginx/html 10 restart: unless-stopped

Start the application

Bash
1# Start services 2docker compose up -d 3 4# Verify container is running 5docker 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.

Need help?

Questions about this guide? Our team and community are here to help.

Stay up to date with the latest offers, discounts and special promotions.

View promotions