Skip to content

How can I set the timezone please? #136

Closed
@NeverWait

Description

@NeverWait

I tried many methods, but it still showed UTC. I tried three methods as follows:
1 RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
2 RUN echo "Asia/Shanghai" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
3 ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
I wrote these commands in the Dockerfile respectively, none of them did work.
Could you tell me how to set the timezone please? Thanks very much

Activity

tianon

tianon commented on Jan 24, 2016

@tianon
Collaborator
NeverWait

NeverWait commented on Jan 24, 2016

@NeverWait
Author

Thanks, I go to have a try now

andyshinn

andyshinn commented on Mar 8, 2016

@andyshinn
Contributor

Based on the Dockerfile shown it looks like tzdata may have indeed been missing. Please reopen if this is still an issue for you. We do pull in tzdata at build time to specifically grab just the UTC timezone file. So, if that is causing issues this could be considered a bug.

kklepper

kklepper commented on May 8, 2016

@kklepper

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
kklepper

kklepper commented on May 9, 2016

@kklepper

On the alpine bug list, Christian Kampka advised

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
/ # 

He also said

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.

I don't understand this, but after adding -U and substituting TZ in the Dockerfile it works now as intended.

danielgusmao

danielgusmao commented on Jan 15, 2017

@danielgusmao

# Install base packages
RUN apk update
RUN apk upgrade
RUN apk add ca-certificates && update-ca-certificates
# Change TimeZone
RUN apk add --update tzdata
ENV TZ=America/Bahia
# Clean APK cache
RUN rm -rf /var/cache/apk/*

renanbr

renanbr commented on Sep 25, 2017

@renanbr

Sorry for commenting on a closed issue, but sometimes I just want to deploy a simple application using Docker Compose with some alpine-based containers inside... then I'm forced to override every dockerfile (or use on-the-fly configuration).

TZ variable works for debian-based images, and it's great :-) Why not for alpine?

Even if it's not a bug, would we consider taking it as an usage issue?

StalkAlex

StalkAlex commented on Nov 1, 2017

@StalkAlex

After using previous code it started to show current time zone as I understand, but time stays as before.
Wed Nov 1 12:12:45 +06>-6 2017
But real time is 18:12:45. Could someone explain me what this is +06>-6 and how setup time correctly?

tianon

tianon commented on Nov 1, 2017

@tianon
Collaborator

@StalkAlex no idea where that +06>-6 is coming from, but the following works fine for me:

$ docker run -it --rm alpine:3.6
/ # apk add --no-cache tzdata
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
(1/1) Installing tzdata (2017a-r0)
Executing busybox-1.26.2-r7.trigger
OK: 7 MiB in 12 packages
/ # export TZ='America/Los_Angeles'
/ # date
Wed Nov  1 10:09:26 PDT 2017

In a Dockerfile, that would look something like this:

FROM alpine:3.6
RUN apk add --no-cache tzdata
ENV TZ America/Los_Angeles

42 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tianon@andyshinn@renanbr@schmunk42@danielgusmao

        Issue actions

          How can I set the timezone please? · Issue #136 · gliderlabs/docker-alpine