Automatically update all your running LXD containers.
While you could perform common management of multiple LXD containers with tools like Ansible or Puppet, in this tutorial we are going to show how to work with a simple script that runs on the host and automatically updates/upgrades all running Debian/Ubuntu-based containers. We could extend the script to perform other tasks or include updates/upgrades for other distributions that have different package managers.
Create a file called “update-containers.sh”
# vi /usr/local/sbin/update-containers.sh
And add the code.
#!/bin/bash # Filter out running Ubuntu and Debian containers RUNNINGVMS=$(lxc list -c ns,config:image.os | grep -i "running" | grep -i -E "Ubuntu|debian" | awk '{print $2}' ) for container in $RUNNINGVMS; do echo "Upgrading container ${container}" lxc exec ${container} -- bash -ilc "apt update && apt upgrade -y" done
Make the file executable.
# chmod +x /usr/local/sbin/update-containers.sh
Now run the script which will automatically update/upgrade all your running Ubuntu/Debian containers.
# /usr/local/sbin/update-containers.sh