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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With