Skip to content

Instantly share code, notes, and snippets.

@supermarsx
Created April 16, 2026 13:42
Show Gist options
  • Select an option

  • Save supermarsx/0424af64b15080f78334a3dc0c10951d to your computer and use it in GitHub Desktop.

Select an option

Save supermarsx/0424af64b15080f78334a3dc0c10951d to your computer and use it in GitHub Desktop.
Portainer CE Auto-Installer & Auto-Updater Script

Portainer CE Auto-Installer & Auto-Updater Script

Zero-touch install / daily self-update via cron.

1 Purpose & highlights

  • Installs or updates Portainer CE to the latest portainer/portainer-ce:latest image
  • Re-creates the container only when a newer image exists
  • Persists data in a named volume portainer_data
  • Verifies the container is running and its HTTPS API on 9443 responds
  • Self-copies to /usr/local/sbin/portainer-auto-update.sh and adds a daily 03:30 cron job
  • Emits clear logs; exits non-zero on any failure

2 Quick one-liner install

curl -fsSL https://gist.githubusercontent.com/supermarsx/a8b61ab7ac05f04c5883cb8179205e77/raw/portainer-ce-auto-install-update.sh | sudo bash

Downloads the raw script and runs it as root.
Safe to re-run anytime; idempotent.

3 Manual usage

# First run (installs Portainer and sets up daily cron):
sudo bash portainer-auto-update.sh

# Disable cron on this run only:
sudo portainer-auto-update.sh --no-cron

# Completely remove the cron job:
sudo portainer-auto-update.sh --remove-cron

# Override the schedule (24-h format, cron syntax):
sudo portainer-auto-update.sh --cron-schedule "15 4 * * *"

4 Configuration knobs (inside the script)

Variable Default What it does
PORTAINER_IMAGE portainer/portainer-ce:latest Image to deploy
CONTAINER_NAME portainer Container name
DATA_VOLUME portainer_data Persistent volume for /data
CRON_SCHEDULE 30 3 * * * Daily update time
STOP_TIMEOUT 30 s Graceful stop before docker kill
WAIT_RUNNING_TIMEOUT 60 s Wait for container to reach Running
WAIT_HTTP_TIMEOUT 90 s Wait for HTTPS API on 9443

5 What the cron job looks like

# Managed by portainer-auto-update.sh — do not edit by hand
30 3 * * * root /usr/local/sbin/portainer-auto-update.sh >>/var/log/portainer-auto-update.log 2>&1

Logs are appended to /var/log/portainer-auto-update.log.

6 Prerequisites

  1. Linux host with Docker Engine running
  2. curl available (for HTTPS health-check)
  3. Root privileges (sudo) to manage Docker, volumes, and cron

7 Troubleshooting tips

Symptom Resolution
“Docker is not installed” error Install Docker Engine and ensure the daemon is active.
Script exits at HTTPS probe Verify port 9443 is reachable and not blocked by a firewall.
Cron doesn’t seem to run Check /etc/cron.d/portainer-auto-update exists and restart cron/crond service.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment