How to Install Docker + docker-compose + Portainer on VPS

How to install Docker + docker-compose + Poratiner on VPS

You probably came here from my other blog post about a Monitoring solution for my services. Here is the link to my blog post in case if not: https://www.jaankivila.com/how-do-i-track-my-online-services/

First of all, you need to get your own Server instance. I suggest you take one from Hetzner Cloud

Great, now you have your own server and can connect to it via SSH. Right?

First thing first – Basic VPS Security

If you did not secure your public-facing server, I suggest you check my guide: Protection of Your Fresh Server (VPS, Dedicated) – 5 Easy steps (open in new tab). Before you continue with the Docker + docker-compose + Portainer installation steps.

Install Docker

Debian 11

Why Debian you may ask? Debian is the most stable and popular Linux distro. Ideal for Home Lab servers. Easy to use with a lot of guides to follow.

# Uninstall old versions

sudo apt-get remove docker docker-engine docker.io containerd runc

# Set up the repository

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

# Add Docker’s official GPG key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Use the following command to set up the repository

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

# Update repository list

sudo apt-get update

# To install the latest version, run

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Voilà, now you can verify that the Docker Engine installation is successful 🎉

# Run the “hello-world” image

sudo docker run hello-world

Do not forget to add your user to the docker group, so you can run containers with a non-root account

# Add docker group (if it was not created earlier)

sudo groupadd docker

# Add your user to the docker group

sudo usermod -aG docker $USER

If you want the docker to start automatically after reboot, you need to enable services

# Enable docker service

sudo systemctl enable docker.service

# Enable containerd.service

sudo systemctl enable containerd.service

Install docker-compose

It is quite simple, just use your regular apt install command

# Install docker-compose

sudo apt install docker-compose

Verify

docker-compose --version

Output

docker-compose version 1.25.0, build unknown

Install Portainer

Portainer is a powerful Docker container management system with a pretty GUI. You can easily install an Open Source Community Edition with only one line.

# Create a new Portainer volume

sudo docker volume create portainer_data

# Deploy Portainer with default SSL port 9443

sudo 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

Now, you can create a new account for Portainer by accessing the Admin panel with your server IP address and secure port 9443. Example: https://yourserverip:9443

If you feel you need more advanced installation, you can always check the official docker docs here:

https://docs.docker.com/engine/install/debian/

One Comment

Leave a Reply