How to Install Portainer CE on VPS

It’s easy to get lost on your own VPS a while after the installation. Also, it’s not easy to get different open-source apps with different dependencies and configs up and running.

Docker exists to solve this portability and manageability problem. Portainer exists to make Docker even easier to manage.

The installation starts with the Docker, I will do it for an Ubuntu 22.04 VPS. The steps are also on Docker documentation here.

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

And actually install Docker:

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

And to make Docker available for non-root user (the user name is “youruser” in this case):

sudo groupadd docker
sudo usermod -aG docker youruser
su - youruser
docker ps

And finally, you should be able to use docker command without sudo from your user.

Installation of Portainer on Docker is extrmely simple (here is the official documentation):

docker volume create portainer_data
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

If you go to the address “https://<your-ip-address>:9443” you should be able to see the Portainer interface. You can create your user and password here and start using Portainer. Please use a complex password, Portainer has a deep control over the system.

The usage is simple, you can create a new stack and typically copy the “docker-compose” file content into the text edit area. Pay attention to the environment variables needs of the docker compose file content, update the content if necessary and start the stack. That’s it, you can set up and self-host farly complex applications by using Portainer and Docker on a server easily.

A final word on security, if you are exposing your Portainer instance to public internet (by the port 9443 or putting it behind a reverse-proxy), your system is at risk. Please at least use a long and complex, non-dictionary password. A more detailed article about the topic can be found here on Portaner blog: https://www.portainer.io/blog/how-to-correctly-secure-portainer-when-presented-on-the-internet

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *