Home > front end >  How to run a docker image with the same time zone as the host machine?
How to run a docker image with the same time zone as the host machine?

Time:04-13

How to tell docker to run any image to pick the time zone settings for the host machine.

This is necessary especially when dealing with time zone related data.

CodePudding user response:

You can set the TZ environment variable to the same as the host like this

docker run --rm -e TZ=$(cat /etc/timezone) debian date

This sets the TZ environment variable to the content of the /etc/timezone file of the host machine.

The above command runs the date command on a debian image to show that it works.

CodePudding user response:

Try using environment variables.

with the docker run command:

docker run -e TZ=America/Los_Angeles <containername>

or in the docker file (you may or may not have to install tzdata, depends on the system):

RUN apk add --no-cache tzdata
ENV TZ America/Los_Angeles
  • Related