Diego Betto's Blog
Docker and Portainer

June 27, 2022 · 1 min di lettura

Portainer: updating your Docker instance the easy way

How to safely update your Portainer instance with a simple bash script, without losing containers or volumes.

Condividi:XLinkedInFacebookWhatsApp

Portainer is a really handy tool for managing your Docker containers, volumes, and networks from a web interface.

One thing that can be scary at first is how to update Portainer. It’s actually very simple and you shouldn’t lose any data.

I use Linux Ubuntu/Debian, so things might be slightly different in your case, but it should be easy to adapt the script. You can create a simple script like this:

#!/bin/bash
sudo docker pull portainer/portainer-ce
sudo docker stop portainer
sudo docker rm portainer

sudo docker run --name portainer --restart=unless-stopped -d -p 8000:8000 -p 9000:9000 \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data portainer/portainer-ce

The script takes care of:

  • updating the local Portainer image
  • stopping the container
  • removing it (not the volume with the data)
  • starting the new container

You can save it in ~/.local/bin under the name update-portainer and then give it execute permissions (with chmod +x ~/.local/bin/update-portainer).

From then on, just run update-portainer from bash and your Portainer container will be updated.

Easy. If you’re also running WordPress on Docker, I’ve written a guide on how to build the stack with wpdockerize too.

Have a good one!

Condividi:XLinkedInFacebookWhatsApp