Created
May 24, 2025 09:53
-
-
Save nikteg/6a33f0aa9dd6f7f65712b64a69cf5d2a to your computer and use it in GitHub Desktop.
Simple script to update portainer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -euo pipefail | |
| # Check if running as root | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "This script requires sudo privileges. Re-running with sudo..." | |
| exec sudo "$0" "$@" | |
| exit | |
| fi | |
| # Create backup | |
| docker run --rm \ | |
| -v portainer_data:/data \ | |
| -v $(pwd):/backup \ | |
| alpine \ | |
| sh -c "tar czvf /backup/portainer_backup_$(date +%Y%m%d_%H%M%S).tar.gz /data" | |
| # Pull latest version | |
| docker pull portainer/portainer-ce:latest | |
| # Stop and remove old container | |
| docker stop portainer | |
| docker rm portainer | |
| # Start new container with new image | |
| 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 | |
| # Add to nginx network for nginx proxy manager support | |
| docker network connect nginx portainer | |
| echo "Successfully updated portainer" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment