3

I'm using Docker 19.03 on Mac but it would be nice if there is a cross-platform solution. I have this Dockerfile ...

FROM microsoft/mssql-server-linux:latest
  
RUN apt-get update
RUN apt-get install unzip -y

ENV TZ=EDT
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN date
...

This does not seem to be doing the job of setting my timezone, because what prints out displays "EDT" but is still showing UTC time

 ---> d8cf39550832
Step 4/13 : ENV TZ=EDT
 ---> Running in 8996c46391f4
Removing intermediate container 8996c46391f4
 ---> e01cb9586f4c
Step 5/13 : RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
 ---> Running in 1972412de76f
Removing intermediate container 1972412de76f
 ---> fffba690cf2b
Step 6/13 : RUN date
 ---> Running in 9921f49b5353
Tue Jul 28 20:15:57 EDT 2020

When this was run, actual Eastern Standard time was 16:15:57. What's the proper way to set time zone to Eastern standard? I also tried "America/New_York" but did no better.

Dave
  • 15,639
  • 133
  • 442
  • 830

2 Answers2

4

The SQL Server image is based on Ubunutu 16.04 (according to its DockerHub reference page). According to the answers to this question, there's a bug in Ubuntu 16.04 with setting the time zone.

Try changing your docker file to:

ENV TZ=America/New_York
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata

You definitely should be setting America/New_York, not EST or EDT.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • I had to run "RUN apt-get install tzdata" before I put in your commands but then the date did display as New York time. Thanks! – Dave Jul 28 '20 at 20:53
  • Interesting. I'd think `tzdata` would have been installed already in the base image - but good to know. :) – Matt Johnson-Pint Jul 28 '20 at 21:45
0

RUN apt-get install tzdata is redundant. You can use EST5EDT.

EDIT: Although apparently this does the job, please check the subtle implication of using EST5EDT instead of America/New_York in @Matt Johnson-Pint's comment below.
Thanks for pointing this up Matt.

FROM microsoft/mssql-server-linux:latest
  
RUN apt-get update
RUN apt-get install unzip -y

ENV TZ=EST5EDT
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN date
Step 6/6 : RUN date
 ---> Running in 6e270d42ef56
Tue Jul 28 17:03:26 EDT 2020
Neo Anderson
  • 5,957
  • 2
  • 12
  • 29
  • 1
    `EST5EDT` will not have the full history of US Eastern Time that is in the tzdb. It should be `America/New_York`. – Matt Johnson-Pint Jul 28 '20 at 21:45
  • I will remove the answer. Thanks for the insight. – Neo Anderson Jul 28 '20 at 21:49
  • @MattJohnson-Pint, I have read this answer(https://stackoverflow.com/a/54950640/13736525) and I understand that an event like this - _European Parliament voted in favor of removing Daylight Saving Time (DST)_ - would not be historically tracked by the UTC+1 but it would be by CET. However, I don't understand how would this affect a computer system from the practical point of view. May I ask this question in a different post or have you answered it already somewhere else? Thank you! – Neo Anderson Jul 28 '20 at 22:33
  • 1
    That's a bit broad of a question. There are *many* scenarios where having an accurate representation of local time changes will matter. For example, scheduling an appointment. – Matt Johnson-Pint Jul 29 '20 at 00:07