Portainer update
From CPA Tech Wiki
Here's a short bash script to update Portainer on Debian (assuming it's running in Docker, the most common setup):
#!/bin/bash
# Update Portainer container
set -e
echo "Stopping Portainer container..."
docker stop portainer
echo "Removing old container..."
docker rm portainer
echo "Pulling latest Portainer image..."
docker pull portainer/portainer-ce:latest
echo "Starting Portainer container..."
docker run -d \
--name portainer \
--restart always \
-p 8000:8000 \
-p 9000:9000 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:latest
echo "Portainer updated successfully!"
docker ps | grep portainer
Or if you prefer a simpler approach using docker compose:
#!/bin/bash
cd /path/to/docker-compose/directory
docker compose pull portainer
docker compose up -d portainer
echo "Portainer updated!"
If Portainer is installed standalone (less common):
#!/bin/bash
PORTAINER_PATH="/opt/portainer"
systemctl stop portainer
cd $PORTAINER_PATH
wget https://github.com/portainer/portainer/releases/latest/download/portainer
chmod +x portainer
systemctl start portainer
echo "Portainer updated!"
Which one do you use? I can refine the script based on your setup. Also, let me know if you need:
- Automatic cleanup of old images
- Backup before update
- Health check validation
