4

I try to run a Docker container with the same timezone as my Docker host. The host timezone is CEST.

When I run :

$ date
Thu Apr 16 11:04:11 CEST 2020
$ docker run -e TZ=CEST debian:buster date
Thu Apr 16 09:04:14 CEST 2020

The container is 2 hours behind the host.

On the other hand, if I set TZ=Europe/Paris, it works as expected :

$ docker run -e TZ=Europe/Paris debian:buster date
Thu Apr 16 11:04:22 CEST 2020

Is this a bug or am I missing something?

Eric Citaire
  • 181
  • 1
  • 9

2 Answers2

4

The timezone is set by default and you need to change it manually.

There are some options:

Set it in the Dockerfile:

ENV TZ=America/Los_Angeles
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

Using volumes to synchronize with your host:

volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"

or

docker run -v /etc/timezone:/etc/timezone:ro

Finally, set it manually but if you restart the container you lose the configuration:

docker run -e TZ=America/New_York ubuntu date
ginerama
  • 216
  • 1
  • 7
  • This doesn't answer the question. As you can see, I'm already using `TZ` environment variable to set the timezone. But in the case of `TZ=CEST`, which is the timezone configured on the host, it has unexpected behavior. – Eric Citaire Apr 16 '20 at 12:22
  • Sorry for the misunderstood. If you try to configure the TZ with `tzselect` you can not use CEST. So As far I can see there is no possible to use TZ=CEST in Debian 10 to set the TZ. You need to use 'Europe/Madrid' or similar. – ginerama Apr 16 '20 at 13:07
1

After some research, it appears that CEST is not a valid value for TZ environment variable. CEST is just a displayable version of CET when the current date is summer.

In fact, if I set TZ to an obviously invalid value, it gives :

$ TZ=FOO date
Fri Apr 17 14:07:56 FOO 2020

Also note that it has nothing to do with Docker.

References :

Eric Citaire
  • 181
  • 1
  • 9