Back to Blog

Setup Portainer on a Linux VPS using Docker

This markdown file provides a step-by-step guide for setting up Portainer on a Linux VPS using Docker. It includes instructions for installing Docker, deploying Portainer, and accessing the Portainer web interface, with an optional section for installing Docker Compose.

Prerequisites

  1. A Linux VPS (Ubuntu/Debian/CentOS) with Docker installed.
  2. Basic knowledge of command-line operations.

Step 1: Update your VPS

Update your package manager to ensure all software is up-to-date:

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker (if not already installed)

If Docker isn't installed, install it with the following commands:

For Ubuntu/Debian:

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=amd64 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
sudo apt update
sudo apt install -y docker-ce

For CentOS:

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker

Verify the Docker installation:

docker --version

Step 3: Install Portainer with Docker

  1. Create a Docker volume for Portainer data persistence:

    docker volume create portainer_data
    
  2. Deploy the Portainer container:

    docker run -d -p 8000:8000 -p 9443:9443      --name portainer --restart=always      -v /var/run/docker.sock:/var/run/docker.sock      -v portainer_data:/data      portainer/portainer-ce:latest
    

Step 4: Access Portainer

  1. Open your browser and go to the following URL:

    https://<your-vps-ip>:9443
    
  2. You'll be prompted to create an admin user and set up your Portainer instance.


Optional: Install Docker Compose (if needed)

If you plan to manage multiple containers or use Docker Compose, install Docker Compose with the following commands:

sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

Portainer Setup Complete!

You now have Portainer set up on your Linux VPS with Docker.