Update Image with Portainer

Update Image with Portainer
Photo by Rubaitul Azad / Unsplash

Managing your docker containers by cli was a pain for me. That's why I set up a docker container with Portainer to manage my running containers and keep the update process as simple as possible.

In this post I won't go into detail how to set up a container, especially because mine are running on a single VPS with traefik, which allows me to provide multiple services inside docker containers. They are still reachable under one IP but with different (sub-) domains.

Keep in mind that my docker containers were set up with docker-compose. Which means that I edited the docker-compose.yml file to pull the latest image when executed. Check your .yml file for the image version otherwise if you pull and recreate the image you might pull a specific (older) version of the image. Especially when using docker-compose in cli to update/recreate.

How to update your containers:

  1. Login to your portainer-website
  2. Select your existing portainer instance
  3. Open Containers located in the sidebar menu
  4. Select your designated container which you want to update f.e. nextcloud
  5. You see "Actions" on the top of the container page
  6. Stop the container
  7. Recreate

Keep in mind that the only data will stay on the container which was mapped to a persistent volume. As I said at the top, I used docker-compose with volumes.

The container will now start with the latest image version. Repeat this steps for all your containers which you want to get updated.

Check image version:

Unfortunatly I don't have any advice to see if your image is out of date with portainer. You can compare the docker-hub with your created image date to see if there is a newer version available. Fell free to take a look at watchtower for automatic image updates.

Update Portainer:

Since you can't use Portainer to update itself you need to update via cli in this case. As I said above I'm using docker-compose with an .yml file so I need to use the following command to update and recreate.

cd /opt/containers/portainer
sudo docker compose pull portainer
sudo docker compose up --build --force-recreate --no-deps portainer
sudo docker compose start portainer

If your service is not called "portainer" you have to edit this command

By the way, the commands above were the original way to update my containers one after another. If portainer fails or you don't want to use it, just edit the commands for you indiviual services.

Remove unused images:

After updating you containers you can check under portainer->images for any unused images. I recommend removing them especially when having limited space on your server or doing backups regularly anyway. Otherwise just leave them there until you know you don't need them anymore.

Troubleshooting:

Code 400: If you are running into a Code 400 error when starting the container open up the developer console of your browser (Default button F12) and check the console for errors. You can see the complete error message from portainer if something went wrong.

Vaultwarden/Server: If you are running a vaultwarden-server container you might get the code 400 after updating your image saying in the console:

failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/bin/dumb-init": stat /usr/bin/dumb-init: no such file or directory: unknown

To solve that problem you need to edit the container image under "duplicate/edit" on the vaultwarden container page to "Entrypoint = Default".

After that you need to "Deploy the container" above and recreate.

Nextcloud: If you are getting the maintenence page when accessing your nextcloud page you need to turn off the maintenence mode manually. Check your app path first on the bottom of your nextcloud container page in portainer:

Connect to your server via ssh , navigate to the given path and add "config" to the path:

cd /opt/containers/nextcloud/app/config
sudo nano config.php

Edit the config.php file on the buttom where it says "'maintenance' => true," back to "false". Save the file and restart the nextcloud container if not stopped. After that you can access your nextcloud page with your browser and update your database. This takes a few seconds but afterwards you will get redirected to the login-page when done.

Depcrecated docker compose commands:

If you are running into this error:

root@vmd88573:/opt/containers/portainer# sudo docker compose up --force-recreate portainer
WARN[0000] /opt/containers/portainer/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 0/0
 ⠋ Container 78c1b2e0a82e_portainer  Recreate                                                                                                             0.0s
Error response from daemon: Conflict. The container name "/78c1b2e0a82e_portainer" is already in use by container "78c1b2e0a82eecbed3c65e57f6c43509d721ae4fa199dd4022870ab021f12907". You have to remove (or rename) that container to be able to reuse that name.

You have to do remove this first:
Note: You have to have the persistent volumes otherwise your data is lost

docker rm -f 78c1b2e0a82eecbed3c65e57f6c43509d721ae4fa199dd4022870ab021f12907

and recreate the container afterwards:

docker compose up -d

Done!