Project

General

Profile

Bug #5543

timezone in docker alpine

Added by Karl Klepper about 3 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
05/04/2016
Due date:
% Done:

100%

Estimated time:
Affected versions:
Security IDs:

Description

According to https://wiki.alpinelinux.org/wiki/Alpine_Linux:FAQ#How_do_I_set_the_local_timezone.3F and http://www.sonoracomm.com/index.php?option=com_content&task=view&id=107&Itemid=32, I added

    echo "CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00" > /etc/TZ

to my RUN commands in my Alpine based docker container (FROM alpine). But it does not work:

/ # cat  etc/TZ
CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00
/ # date
Wed May  4 14:15:13 GMT 2016

Actually the time should be 16:15:13. Changing the TZ content does not change anything:

/ # cat  etc/TZ
CET-3CEST-4,M3.5.0/02:00:00,M10.5.0/03:00:00
/ # date
Wed May  4 14:44:22 GMT 2016

What am I missing here?

History

#1 Updated by Jakub Jirutka about 3 years ago

The wiki page you’ve mentioned is quite clear about setting timezone – you should use `setup-timezone`. The method you’ve tried works on pre 2.2 versions (the latest version is 3.3) as is clearly described on the wiki page.

#2 Updated by Karl Klepper about 3 years ago

Thank you very much for the hint, Jakub, but this doesn't help here:

$ docker exec -it m1 ash
/ # setup-timezone
ash: setup-timezone: not found

#3 Updated by Christian Kampka about 3 years ago

Both resources are outdated, as alpine does not use uClibc but musl libc.
musl defaults to /etc/localtime when the TZ environment variable is unset.
Usually, /etc/localtime is a symlink to a timezone definition in the tzdata package.

#4 Updated by Karl Klepper about 3 years ago

Thanks Christian. Then why does this not work? (Usually people set a soft link, but even copy doesn't do the trick.)

@ENV TERM=xterm \
TZ=Europe/Berlin

RUN apk --update add nginx php-fpm php-memcache php-mysqli php-ctype php-zlib tzdata && \
... (some stuff)
cp /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
apk del tzdata@

#5 Updated by Christian Kampka about 3 years ago

Karl Klepper wrote:

Thanks Christian. Then why does this not work? (Usually people set a soft link, but even copy doesn't do the trick.)

Not sure what you mean by "does not work".
This is how it should work. If it does not, you need to provide a more detailed description of your problem.


docker run -it --rm alpine /bin/sh
/ # date
Sun May 8 20:46:18 UTC 2016
/ # apk add -U tzdata
fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.3/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tzdata (2015g-r0)
Executing busybox-1.24.1-r7.trigger
OK: 8 MiB in 12 packages
/ # cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime
/ # date
Sun May 8 22:46:45 CEST 2016
/ #

As a side note, if you want to rely on the TZ environment variable, you cannot remove tzdata, but that should not apply if you set /etc/localtime correctly.

#6 Updated by Karl Klepper about 3 years ago

Thank you very much. I could reproduce your code and then adapt to my Dockerfile. It works now. I don't need TZ.

#7 Updated by Christian Kampka about 3 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

#8 Updated by Karl Klepper about 3 years ago

Thanks again, Christian!

#9 Updated by Natanael Copa about 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF