brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: TZ only sets a Docker container's clock when the image has tzdata

Docker
~/tips/tip-docker-timezone-tzdata

docker run --rm -e TZ=Europe/Amsterdam alpine date

Fix container logs in UTC when setting TZ seemingly does nothing.

You set TZ=Europe/Amsterdam on a container and the logs still show UTC. The variable is fine; the image is missing the timezone database that tells it what Amsterdam means.

docker run --rm -e TZ=Europe/Amsterdam alpine date
docker run --rm -e TZ=Europe/Amsterdam php:8.3-cli date

The plain Alpine image prints UTC, because it ships without the tzdata package. The Debian based PHP image has it and prints the local time. Small images often leave it out to save space.

Two fixes. If you build the image yourself, add the package, for example apk add tzdata on Alpine. If you do not, mount the host’s local time file read-only:

docker run --rm -v /etc/localtime:/etc/localtime:ro alpine date

That gives the container the host’s current zone, without any database inside.

I would set both TZ and the mount in Compose files; between them, almost every image gets it right. The mount copies only the current rules, so TZ stays useful for apps that read the variable directly. Some apps ignore the system clock entirely and have their own timezone setting, often in their web UI, so check there too before you blame the container.

Further reading: Alpine Linux wiki: setting the timezone, docker container run

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link