I've created a docker container, which is running in the wrong timezone. I personally need it to run in my timezone (Europe/Stockholm, GMT+1). Since the project is open source, other users may also wish to change that. I wish to make it easy for anyone to change this in e.g. the Dockerfile or in the docker-compose.yml.
If possible, I also wish that the solution is applicable not only on CentOS in case someone wishes to use a different distro.
What is the most distro-agnostic approach to set the localtime/timezone in my docker container?
These two approaches seem to be common but I'm not sure if they are really the best way forward for me:
TZ environment variable
Some Linux distros read the TZ environment variable. However, I'm noticing it doesn't work when I use the
You can map the container's
/etc/localtime on the host in the docker-compose.yml. But when doing this, distros that use
/etc/timezone is left at UTC and software which may be reading that will then read the wrong timezone.