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 centos:7
image.
/etc/localtime
You can map the container's /etc/localtime
to /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.
/etc/localtime
is the ultimate fallback location. I don’t understand your last paragraph on it, though. It’s a symlink in most cases. Copying the actual file to the container should produce the desired result. – Daniel B May 16 '16 at 11:32/etc/localtime
it seems some software rely on/etc/timezone
. So therefore I was wondering if the/etc/localtime
approach was really the best one. – fredrik May 16 '16 at 11:35/etc/localtime
is available virtually everywhere, including OS X and FreeBSD. – Daniel B May 16 '16 at 11:43