English

Install Docker on a Linux VPS

3 min
VPS/VDS Hosting

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
# Update package list sudo apt update # Update installed packages sudo apt upgrade -y

Step 2: Install dependencies

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

Step 3: Add Docker's official GPG key

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

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

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

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
# Start Docker service sudo systemctl start docker # Enable Docker on boot sudo systemctl enable docker

Step 6: Verify installation

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

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

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

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

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

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

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

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

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

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

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

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

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
# Create a directory for your project mkdir my-project cd my-project # Create docker-compose.yml file nano 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
# 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.

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

View promotions

We use cookies

We use analytics cookies to improve your experience on our site. No data is sold to third parties. Learn more in our privacy policy.