Best practice for upgrading an image of a container

Hi. I am running a container which is using alpine:3.10. I didn’t create a custom image, I used stock image available in lxd repository and modified a running container for my needs (installed nginx, added some php etc.). Now 3.10 is quite outdated and I wanted to upgrade it to 3.15. What is considered to be the most desirable approach in keeping container state up-to-date in terms of OS version. I can see the following options but not sure if it is a good approach:

  1. Create a custom image and upgrade that image when it is time to do so. Then I can delete old container and create a new one. It may work for stateless containers well. But not sure if it is a very convenient way for a database for example. I would need to backup it first and then restore from a backup.
  2. Upgrade distribution inside container. I haven’t tried it. But I believe container’s metadata will still show that this container is based on the old image. Can I manipulate that? If yes is it a good approach?
  3. Somehow do a snapshot of stateful folders of a container. Create a new container based on the latest image, apply snapshot. Delete old container. Is it possible to do? Is there any guide for that?

I rarely use Alpine but for Debian/Ubuntu, I usually go with 2), just treat it like a long running Linux system and go through normal package updates.

For the metadata, if it’s important to you, you can use lxc config edit to change it to match the current release after your upgrade.

If going with 1), then you probably would want to move as much of the data to separate custom storage volumes which you can re-attach to your new container.

1 Like