Using Alpine as a base for my Docker images

What makes Alpine great is that it’s tiny. What doesn’t make it great is when weird things happen. Here I document potential fixes for potential problems.


It is standard practice to create an Environmental Variable called TZ. For me, I set this to Australia/Perth, however Alpine does not honour Docker’s Timezone system, and so we have do do this ourselves in our container’s first time startup script. I found this to be reasonably simple, while still maintaining support for the TZ environmental variable.

apk --update add tzdata
cp /usr/share/zoneinfo/$TZ /etc/localtime
echo "$TZ" > /etc/timezone
apk del tzdata
rm -rf /var/cache/apk/*
rm -rf /usr/share/zoneinfo

namei: command not found

The namei utility is used to determine information about every “node” in a path name, and is capable of following symlinks. I found that this was not installed by default, so naturally, I had to install it. It is bundled in the util-linux package.

apk --update add util-linux

timeout: unrecognized option: preserve-status

Alpine uses an older version of Busybox, which misses the –preserve-status option. You can either update to a newer version of busybox, or you can install the coreutils package which includes a version of timeout which has –preserve-status implemented.

apk --update add coreutils

One way of upgrading busybox within the Alpine container, is to rip it directly out of the BusyBox container in your dockerfile like so:

FROM alpine:3


COPY --from=busybox:stable-musl /bin/busybox /bin/busybox