Skip to content

🐳 Installing Portainer

portainer-banner

Portainer is a powerful, enterprise grade Container Service Delivery Platform. It simplifies the management of Docker images/containers/volumes by providing a powerful GUI. It can be downloaded and installed as a Docker container.

portainer

Info

The project is open-source and can be downloaded here: https://www.portainer.io.


πŸ“₯ Installation

πŸ“‹ Requirements

Info

Portainer requires the installation of


🐳 Install Portainer

The use of Docker Compose will automate the installation of portainer container.

This will install portainer community-edition which is free for personnal use only.

πŸ”§ Setup Portainer Parameters

Before deploying, you need to define a few environment variables that will be used throughout the setup process.

  • HOST_PORT: external port used by NGINX to route traffic to the service
# example of configuration for environment parameters
HOST_PORT=9000
βš™οΈ Configure Portainer for Docker Compose

Portainer can be deployed using Docker Compose. The compose.yml file will automatically incorporate the environment variables configured in the previous step. You can copy, paste, and run all of the following commands directly in your terminal.

# create docker directory
mkdir portainer && cd portainer
mkdir data
# setup of compose.yml
tee compose.yml > /dev/null <<EOF
services:
  portainer:
    container_name: portainer
    user: "\${PUID}:\${PGID}"
    image: portainer/portainer-ce:latest
    volumes:
      - ./data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - \${HOST_PORT}:9000
    restart: unless-stopped
EOF
# setup of .env file
tee .env > /dev/null <<EOF
###################################################################################
# Run as non-root user
###################################################################################
PUID=`id -u`
PGID=`id -g`

###################################################################################
# NGINX Proxy Configuration
###################################################################################
HOST_PORT=${HOST_PORT}
EOF

Save the .env informations

All the secret informations are defined in the .env file.

🐳 Install Portainer with Docker Compose

Now that the compose.yml file has been generated, it's time to install all the containers.

# install and start the container
docker compose up -d
Fix portainer permission issue on file: /var/run/docker.sock
# create the systemd docker-rights service to force socket user and rights
sudo tee /etc/systemd/system/docker-rights.service > /dev/null <<EOF
[Unit]
Description=Set Docker Socket User and Rights
Before=docker.service
Requires=docker.socket

[Service]
ExecStart=/usr/bin/setfacl --modify user:${USER}:rw /var/run/docker.sock

[Install]
WantedBy=multi-user.target
EOF

# enable docker service and restart
sudo systemctl enable docker-rights.service
sudo reboot

πŸš€ Deploy Portainer

Install NGINX

NGINX needs to be installed, follow the NGINX section.

Configure NGINX

NGINX needs to be configured using a file in /etc/nginx/sites-available directory.
This configuration file specify the documentation path:

server {
  server_name portainer.domain.fr;

  # setup 404 error_page
  error_page 404 /404.html;
  include snippets/error-404.conf;

  # reverse proxy
  location / {
    proxy_pass http://127.0.0.1:9000;

    # keep it HTTP/1.1 and enable WebSockets
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;

    # forwarded headers
    include proxy_params;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port $server_port;

    # timeouts for long-running websocket/exec sessions
    proxy_read_timeout 3600;
    proxy_send_timeout 3600;

    # avoid buffering for interactive streams
    proxy_buffering off;
  }
}
# enable site for production
sudo ln -s /etc/nginx/sites-available/portainer.domain.fr /etc/nginx/sites-enabled/portainer.domain.fr

# restart nginx
sudo nginx -t && sudo service nginx restart

Replace portainer.domain.fr by the name of your website.

Activate HTTPS

To activate HTTPS protocol, follow theΒ Let's Encrypt section.

In case of Unable to verify administrator account existence

To create the default admin account with its password, type the following url: https://portainer.domain.fr/#!/init/admin.