skip to Main Content

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.

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search