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
-
In portainer, go to Networks and select + Add network
-
Name it: macvlanconfig
-
For Driver select: macvlan
-
For Parent network card insert your networkcard name
You can find your network name by doing ifconfig in your SSH console
- 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
-
Click Create the network
-
Select again + Add network
-
Name it: LAN
-
For Driver select: macvlan
-
Select Creation I want to create a network from a configuration
-
For Configuration select: macvlanconfig
-
Select Enable manual container attachment Make sure its on.
-
Click Create the network
Attaching LAN to a container
-
Go to Containers and select for example pihole
-
Click on Duplicate/Edit
-
Click on Network
-
For Network select: LAN
Optional: You can set the hostname to pihole01 for example to recognize the hostname better
- 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