ITGOIT - Wiki

Portainer

cd /home/myusername
mkdir docker && cd "$_"
mkdir portainer && cd "$_"

nano docker-compose.yml

services:
  portainer:
    image: portainer/portainer-ce:latest # For Business Edition use: portainer/portainer-ee:latest
    container_name: portainer
    restart: always
    volumes:
      - ./data:/data
      - /var/run/docker.sock:/var/run/docker.sock
    ports:
      - 9443:9443 # HTTPS
      - 9000:9000 # Optional: required for accessing the UI over HTTP (legacy reasons)
#      - 8000:8000 # Optional: required only for Edge Agents and Edge compute features
docker compose up -d

Update Portainer

cd /home/myusername/docker/portainer
docker compose down
docker pull portainer/portainer-ce:latest
docker compose up -d

Configure Portainer

You can add the following link to get a lot of templates Settings --> App Templates
https://raw.githubusercontent.com/Qballjos/portainer_templates/master/Template/template.json

Old version: https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json

macvlan

  1. In portainer, go to Networks and select + Add network

  2. Name it: macvlanconfig

  3. For Driver select: macvlan

  4. For Parent network card insert your networkcard name

You can find your network name by doing ifconfig in your SSH console

  1. For IPV4 Network configuration you set your own network a example:

Subnet: 192.168.1.0/24
Gateway: 192.168.1.1
IP range: 192.168.1.0/24

  1. Click Create the network

  2. Select again + Add network

  3. Name it: LAN

  4. For Driver select: macvlan

  5. Select Creation I want to create a network from a configuration

  6. For Configuration select: macvlanconfig

  7. Select Enable manual container attachment Make sure its on.

  8. Click Create the network

Attaching LAN to a container

  1. Go to Containers and select for example pihole

  2. Click on Duplicate/Edit

  3. Click on Network

  4. For Network select: LAN

Optional: You can set the hostname to pihole01 for example to recognize the hostname better

  1. Click on Deploy the container

Sourch: How To Setup MacVLAN in Portainer: https://www.youtube.com/watch?v=o7nn6Tv-PAw

Backup Portainer

cd /home/myusername
mkdir scripts backups
cd scripts
nano portainer-backup.sh
#!/bin/bash

# Set the Portainer container name
CONTAINER_NAME="portainer"

# Set the backup directory
BACKUP_DIR="/home/myusername/backups/portainer"

# Create a new directory for the backup
BACKUP_DATE=$(date +"%Y-%m-%d_%H-%M-%S")
BACKUP_PATH="$BACKUP_DIR/$BACKUP_DATE"
mkdir -p "$BACKUP_PATH"

# Copy the Portainer data directory from the container to the backup directory
docker cp "$CONTAINER_NAME":/data "$BACKUP_PATH"

# Compress the backup directory
tar -czf "$BACKUP_PATH.tar.gz" -C "$BACKUP_DIR" "$BACKUP_DATE"

# Remove the uncompressed backup directory
rm -rf "$BACKUP_PATH"

# Prune old backups (keep the last 7 days)
find "$BACKUP_DIR" -name "*.tar.gz" -type f -mtime +7 -delete
sudo chmod +x portainer-backup.sh

Test the script

sudo portainer-backup.sh

Schedule the script to run every 24 hours using cron

sudo crontab -e
# This cron job runs at midnight every day (0 0 * * *)
# and executes the script located at /home/myusername/scripts
0 0 * * * /home/myusername/scripts/portainer-backup.sh