Guides / Linux servers

Security updates on Alpine Linux servers: apk upgrade on a schedule

beginnerUpdated 26 Nov 2026627 words

Alpine Linux does not come with a tool like unattended-upgrades or dnf-automatic. Updates come from apk upgrade, and on a server you schedule it yourself. A daily job in the crond of BusyBox does that. Every Alpine server also needs a branch upgrade before its branch ends.

For Alpine as a container base image, the steps are different: rebuild the image on a current tag instead of upgrading inside a running container. See keeping Docker images updated.

See what is pending

apk update
apk version -l '<'

apk update downloads the current package indexes. apk version -l '<' lists the installed packages that have a newer version in the repositories. To see what apk upgrade would do without changing anything:

apk upgrade --simulate

apk does not have a security-only mode: apk upgrade installs every update of the branch you are on.

Upgrade on a schedule

Alpine runs the scripts in /etc/periodic/daily once a day from the crontab of root. Add one:

cat > /etc/periodic/daily/apk-upgrade <<'EOF'
#!/bin/sh
# Daily package upgrade from the Alpine repositories of this release.
apk update --quiet && apk upgrade --quiet 2>&1 | logger -t apk-upgrade
EOF
chmod 755 /etc/periodic/daily/apk-upgrade

The crontab of root runs /etc/periodic/daily at 02:00:

0	2	*	*	*	run-parts /etc/periodic/daily

That only happens while crond runs. On a minimal installation it can be off:

rc-update add crond default
rc-service crond start

Use a name without a dot all the same (apk-upgrade, not apk-upgrade.sh): the BusyBox run-parts of Alpine 3.24 runs both, but the run-parts of other systems skips names with dots, and the habit avoids surprises when you copy the script.

Test the job once by hand and read the result in the system log:

run-parts /etc/periodic/daily
grep apk-upgrade /var/log/messages

run-parts --test /etc/periodic/daily lists the scripts that would run, without running them.

After a kernel upgrade

Alpine keeps one kernel version installed. After an upgrade of linux-lts or linux-virt, the modules of the running kernel are gone from /lib/modules, so loading a module (for example for a new firewall rule or a Docker network) can fail until the next boot. Compare:

uname -r
ls /lib/modules

When they differ, plan a reboot. The reboot guide covers the rest.

Move to a new branch

Each stable branch gets fixes in the main repository for about two years, and the community repository only until the next stable branch is out (dates in the end-of-life guide). The daily job keeps a server on its branch; moving to the next branch is a manual step:

cat /etc/alpine-release
sed -i 's|/v3\.23/|/v3.24/|g' /etc/apk/repositories
apk update
apk upgrade --available
sync
reboot

--available resets every package to the version available in the repositories you configured, even where that is a lower version. Read the release notes of the new branch first; they list removed packages and changed defaults.

Branches can be skipped. In a test, a container on 3.20 moved to 3.24 in one step: apk first upgraded itself from apk-tools 2 to apk-tools 3, then continued with the other packages.

Check the result

cat /etc/alpine-release
apk version -l '<'     # only the header line when everything is current
uname -r               # after the reboot, matches /lib/modules

Patchbrief reads the installed packages of each server every day and matches them with the Alpine security database, so a fixed CVE that is not installed yet shows up with the apk upgrade line that fixes it.

Sources

Check your servers every day

The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.

Start free