sql-serverdockertimezonedockerfile

How do I set timezone for my docker container?


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.


Solution

  • 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.