Update all LXD containers at once
![Featured image](https://carrondo.pt/images/2021-09-07-update-all-lxd-containers-at-once.jpg)
The task
I need to update all guest OS running inside lxd containers with minimun risk and effort.
The basic concepts
To avoid having to enter each container and running update task(s), script must be ran from host system.
All my containers run Ubuntu or Debian, that simplifies the process a lot…
I use LXD snap version.
The solution
I have created this script to run on demand, but if you feel like a lucky rock star you can cron it…
(If you plan on run it on demand you can remove the ‘-y’ to be able to cancel full-upgrade process)
Filename example <lxd-updates.sh>:
#!/bin/sh
CONTAINERS="$(ls /var/snap/lxd/common/lxd/containers/)"
for container in $CONTAINERS; do
echo "$(date): Updating $container..."
lxc snapshot $container
lxc exec $container -- apt update
lxc exec $container -- apt -y full-upgrade
done
echo "$(date): Update done!"
Make the file executable:
$ chmod +x lxd-updates.sh
And run it:
$ ./lxd-updates.sh
Done!
Relax and grab a coffee…