Update

To keep a Debian/Ubuntu system up to date, we usually do something like this:

apt update
apt upgrade
apt full-upgrade
apt dist-upgrade

What about Docker containers?

Usually it is not convenient to do that kind of update/upgrade inside a docker container. What we do instead is:

  • pull an updated version of the base docker image

  • rebuild the local image (if needed)

  • rebuild the container

  • etc.

We can do this kind of update/upgrade (build a new container and throw away the old one) because usually the data and configuration of the application are stored outside the container. So, the newly built container can reuse them. Or, in some cases, we can modify automatically the configuration of the new container (with the help of scripts).

Most of docker-scripts applications can be updated just with a ds make, which will rebuild the container, customize automatically its configuration (if needed), and reuse the same data and/or configs (which are stored on the directory of the container).

Some docker-scripts applications may be a bit different, or may require additional steps. For example we may need to use ds remake for some of them (instead of ds make), which usually makes a backup of the application first, then rebuilds it (with ds make), and finally restores the latest backup.

To automate the update of all the installed applications, it is recommended to write a script, for example at /var/ds/_scripts/update.sh, with all the required steps. It depends on what applications you have installed, but it may look like this:

Script: /var/ds/_scripts/update.sh
#!/bin/bash -x

# update the system
apt update
apt upgrade --yes

# get the latest version of scripts
cd /opt/docker-scripts/
./git.sh pull

# update ds
cd /opt/docker-scripts/ds/
make install

# get the latest version of ubuntu image
docker pull ubuntu:22.04

# run 'ds make' on these apps
app_list="
    sniproxy revproxy mariadb redis
    galene.example.org
    mattermost.example.org
    "
for app in $app_list ; do
    cd /var/ds/$app/
    ds make
done

# run 'ds remake' on these apps
app_list="
    linuxmint
    lxde1    $(: debian-desktop)
    guac.example.org    $(: guacamole)
    toot.example.org    $(: mastodon)
    "
for app in $app_list ; do
    cd /var/ds/$app/
    ds remake
done

# nextcloud
cd /var/ds/cloud.example.org/
ds update

# moodle
cd /var/ds/moodle.example.org/
ds update
ds remake

# discourse
cd /var/ds/talk.example.org/
ds upgrade

# indico
cd /var/ds/events.example.org/
docker pull dockerscripts/indico
ds make

# bookdown
ds /var/ds/misc/books.example.org/
docker pull dockerscripts/bookdown
ds make

# gitea
ds /var/ds/misc/gitea.example.org/
docker pull dockerscripts/gitea
ds make

# linuxmint
cd /var/ds/mate1/
ds build
ds users backup
ds make
ds users restore $(ls backup/*.tgz | tail -1)

# clean up
docker system prune --force

The script /opt/docker-scripts/git.sh may look like this:

/opt/docker-scripts/git.sh
#!/bin/bash

options=${@:-status --short}
for repo in $(ls -d */)
do
    echo
    echo "===> $repo"
    cd $repo
    git $options
    cd -
done