I'm using Docker 19. I have the following Dockerfile. Notice how I set the time zone to US EST ...
FROM microsoft/mssql-server-linux:latest
RUN apt-get update
RUN apt-get install unzip -y
RUN apt-get install tzdata
ENV TZ=America/New_York
RUN ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && dpkg-reconfigure -f noninteractive tzdata
...
Is there any way I can author my file such that the time zone gets set to the local machine that it's running on? I'm on Central time zone but have team mates in other time zones. If it's useful, the above is part of a docker-compose file that looks roughly like this ...
version: "3.2"
services:
sql-server-db:
build: ./
container_name: sql-server-db
image: microsoft/mssql-server-linux:2017-latest
ports:
- 1433:1433
Some of us are on Macs, but it's possible for folks to be on Windows or Ubuntu. If it's easier you can consider that everyone is on Macs.
Docker containers don't inherit the host's timezone, so you can run into unexpected scheduling issues that wreak havoc with your application. The container is using the UTC timezone, creating a one hour difference between the two times.
The directory /usr/share/zoneinfo in Docker contains the container time zones available. The desired time zone from this folder can be copied to /etc/localtime file, to set as default time. The containers created out of this Dockerfile will have the same timezone as the host OS (as set in /etc/localtime file).
using docker run command:
-e TZ=`ls -la /etc/localtime | cut -d/ -f8-9`
Source
if you still want to use volumes you need to share /etc form the Docker UI in your MAC "Prefernces --> Resources --> FILE SHARING"
Update
for docker-compose :
under build section use:
args:
- TZ
and then:
environment:
- TZ=${TZ}
and then start it like - after re-build -:
export TZ=`ls -la /etc/localtime | cut -d/ -f8-9` && docker-compose up -d --build
you can set the time zone whatever you want in your host machine then you can map your local time to the container through volume mapping. Like this,
volumes:
- /etc/localtime:/etc/localtime
For mac the location of localtime could be different. You can mount that location through volume mapping.
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