Perl programmer for hire: download my resume (PDF).
John Bokma's Hacking & Hiking

Timezones in Alpine Docker Containers

June 14, 2021

In the evening I noticed the container I was running to create my tumblelog Plurrrr ran in timezone GMT, not GMT + 2:00. Excerpt from the generated JSON feed:

...
         "date_published": "2021-06-14T23:59:59+00:00",
         "id": "https://plurrrr.com/archive/2021/06/14.html",
...

Adding the tzdata package to the installation step in the Docker image:

# syntax=docker/dockerfile:1
FROM alpine:latest AS base

WORKDIR /app

FROM base AS builder

RUN apk add --no-cache --virtual .build-deps \
        make wget gcc musl-dev perl-dev \
        perl-app-cpanminus \
    && apk add perl cmark-dev tzdata \
    && cpanm URI JSON::XS YAML::XS Path::Tiny CommonMark Try::Tiny \
    && apk del .build-deps

FROM base AS run
COPY --from=builder /usr/bin/perl /usr/bin
COPY --from=builder /usr/lib/ /usr/lib/
COPY --from=builder /usr/share /usr/share
COPY --from=builder /usr/local /usr/local

COPY tumblelog.pl .
WORKDIR /data
ENTRYPOINT ["perl", "/app/tumblelog.pl"]

And adding an environment variable to the docker run command solved this issue. In my case I used -e TZ="Europe/Amsterdam". Example of how I run the Perl version of tumblelog:

docker run --rm --volume "`pwd`:/data" --user `id -u`:`id -g` \
        -e TZ="Europe/Amsterdam" \
        tumblelog/perl --template-filename plurrrr.html \
                       --author 'John Bokma' \
                       --description "John Bokma's tumblelog" \
                       --blog-url https://plurrrr.com/ \
                       --date-format '%a %d %b %Y' \
                       --tags \
                       --name 'Plurrrr' \
                       --output-dir htdocs \
                       --css soothe.css \
                       --quiet \
                       plurrrr.md

Related