How to Install Docker on a VPS

Docker is a powerful platform that enables you to build, deploy, and manage applications in containers. This guide walks you through the steps to install Docker on your VPS.


Step 1: Update Your VPS System

  • Log In to Your VPS:
    Use SSH to access your VPS:

    ssh user@your-vps-ip
    
  • Update System Packages:
    Before installing Docker, update the package manager and upgrade existing packages:

    sudo apt update && sudo apt upgrade -y
    

Step 2: Install Required Packages

  • Install Dependencies:
    Docker requires a few prerequisite packages. Install them using:
    sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
    

Step 3: Add Docker's Official GPG Key and Repository

  • Add Docker GPG Key:
    Import Docker's GPG key for secure installation:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
    
  • Add Docker Repository:
    Add Docker's stable repository to your system:

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    

Step 4: Install Docker

  • Update the Package Manager Again:
    Refresh the package list to include Docker's repository:

    sudo apt update
    
  • Install Docker Engine:
    Install the Docker Engine:

    sudo apt install -y docker-ce docker-ce-cli containerd.io
    

Step 5: Verify Docker Installation

  • Check Docker Version:
    Confirm the successful installation by running:

    docker --version
    
  • Run a Test Container:
    Verify Docker's functionality by running a test container:

    sudo docker run hello-world
    
    • If successful, Docker will download and run the "hello-world" container, displaying a confirmation message.

Step 6: Manage Docker as a Non-Root User (Optional)

  • Add Your User to the Docker Group:
    To avoid using sudo with every Docker command, add your user to the Docker group:

    sudo usermod -aG docker $USER
    
  • Apply the Changes:
    Log out and back in to apply group changes, or run:

    newgrp docker
    

Step 7: Enable and Start Docker on Boot

  • Enable Docker Service:
    Ensure Docker starts automatically after a reboot:

    sudo systemctl enable docker
    
  • Start Docker Service:
    Start the Docker service if it isn't already running:

    sudo systemctl start docker
    

Step 8: Test Docker Installation with a Sample Image

  • Run an Nginx Container:
    To further test Docker, run an Nginx web server container:
    docker run -d -p 80:80 nginx
    
    • Visit your VPS's IP address in a browser to see the Nginx welcome page.

Step 9: Keep Docker Updated

  • Update Docker Periodically:
    Regularly update Docker to the latest stable version using:
    sudo apt update && sudo apt upgrade -y
    

By following these steps, Docker is successfully installed and configured on your VPS. For advanced Docker usage or troubleshooting, contact QuickServers support.

Was this answer helpful? 0 Users Found This Useful (0 Votes)