Automate Docker, Compose & Portainer Updates

Saurab ThakurSaurab Thakur
3 min read

If you’re running a home server or NAS using OpenMediaVault or any Debian-based system, keeping Docker and Portainer up to date is essential for security and performance. In this guide, you’ll learn how to create a shell script to automate updates and schedule it to run every Sunday at 3:30 AM using cron. You’ll also set a daily shutdown at 4:00 AM to save electricity.

📦 Step 1: Create the Update Script

  1. Create the script file using nano:
nano /usr/local/bin/update-docker-stack.sh
  1. Copy and paste the following script into the file:
#!/bin/bash
echo "🔄 Updating Docker on Debian/OMV..."
sudo apt update
sudo apt install --only-upgrade -y docker-ce docker-ce-cli containerd.io
sudo systemctl restart docker
echo "✅ Docker version:"
docker --version
echo "🔄 Updating Docker Compose..."
DOCKER_COMPOSE_PATH="/usr/local/bin/docker-compose"
if [ -f "$DOCKER_COMPOSE_PATH" ]; then
    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o $DOCKER_COMPOSE_PATH
    sudo chmod +x $DOCKER_COMPOSE_PATH
    docker-compose --version
else
    echo "⚠️ Docker Compose binary not found at $DOCKER_COMPOSE_PATH"
fi
echo "🔄 Updating Portainer..."
docker stop portainer && docker rm portainer
docker image rm portainer/portainer-ce
docker pull portainer/portainer-ce:latest
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
echo "✅ Portainer updated!"
  1. Save the script and exit nano by pressing:
CTRL + X

Then press Y to confirm saving, followed by Enter to confirm the file name. 4. Make the script executable:

sudo chmod +x /usr/local/bin/update-docker-stack.sh

🎯 Run the Script

To update Docker, Docker Compose, and Portainer:

sudo update-docker-stack.sh

🗓️ Step 2: Schedule Weekly Auto Update Using Cron

Now schedule the script to run every Sunday at 3:30 AM using cron.

📌 Edit Root Crontab

sudo crontab -e

🕒 Add This Line

30 3 * * 0 /usr/local/bin/update-docker-stack.sh >> /var/log/docker-update.log 2>&1

This means:

  • 30 3: Run at 3:30 AM
    • *** * 0**: Every Sunday

The output will be saved to /var/log/docker-update.log for future reference.

⚡ Step 3: Daily Automatic Shutdown at 4:00 AM

To save energy, you might want your server to shut down daily at 4:00 AM.

🧾 Add Another Cron Entry

sudo crontab -e

And add this line:

0 4 * * * /sbin/shutdown -h now

This command will halt the system every day at 4:00 AM.

📋 Final Thoughts

With this setup, your server will stay up-to-date with the latest Docker ecosystem updates and shut down gracefully each day to conserve power. This is perfect for home NAS users, Raspberry Pi setups, or OpenMediaVault users who don’t need 24/7 uptime.

Want to receive a Telegram alert after the update finishes? Stay tuned for our next guide on integrating Telegram bots into your scripts!

Share this article

You might also like

Table of contents