1

I've some issues to have similar timezone in all containers of a docker-compose stack.

I tried to add TZ=Europe/Paris as environment variable to containers, and also tried to use :

volumes:
  -v /etc/timezone:/etc/timezone:ro
  -v /etc/localtime:/etc/localtime:ro

For now, it works (bind of /etc/timezone) on Debian/Ubuntu based containers, but not in Alpine based ones.

What's the best practice and/or what does work on all Linux containers ?

1 Answer 1

2

use volume to change the timezone , is not great . you are introducing many dependencies between the host and the container . If you are running in kubernetes or hosted environment , you can not control the timezone of the host .

I will recommends to use the TZ variables .

For ubuntu , i was able to set TZ variable if my image have already the package tzdata.

FOR UBUNTU 18.04/19.04/19.10

These does not work

for V in 18.04 18.10 19.04 19.10
do
   docker run -e TZ=America/New_York -it ubuntu:${V} /bin/bash -c date
done

But these

for V in 18.04 18.10 19.04 19.10
do
    docker run -e TZ=America/New_York -it ubuntu:${V} \
       /bin/bash -c '( export DEBIAN_FRONTEND=noninteractive ; apt-get update ; apt-get install tzdata ) >/dev/null 2>&1 ; date'
done

*FOR DEBIAN STRETCH / BUSTER *

these are working

docker run -e TZ=America/New_York -it debian:stretch /bin/bash -c date
docker run -e TZ=America/New_York -it debian:buster-slim /bin/bash -c date
docker run -e TZ=America/New_York -it debian:buster /bin/bash -c date
docker run -e TZ=America/New_York -it debian:stretch-slim /bin/bash -c date

FOR ALPINE

This is working :

docker run -e TZ=America/New_York -it alpine:3.10 date

This is not working :

docker run -e TZ=America/New_York -it alpine:3.10 /bin/sh -c '(apk update ; apk add tzdata)>/dev/null 2>&1  ; date '

FOR CENTOS

these are working

 for V in 6 7 8 ; 
 do  
      docker run -e TZ=America/New_York -it centos:${V}  /bin/bash -c date ; 
 done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .