aspnet / aspnet-docker

[Archived] ASP.NET Core Docker images for 1.x. Go to https://github.com/dotnet/dotnet-docker for 2.1 and up.
https://asp.net
719 stars 171 forks source link

Can't set timezone on 2.0.5 based images #357

Closed Ettery closed 6 years ago

Ettery commented 6 years ago

We are moving our .NET Core APIs from v1.1 to v2. With microsoft/aspnetcore:1.1.2 I used RUN echo "Africa/Johannesburg" > /etc/timezone in the Dockerfile to set the timezone.

VERBOSE: Step 8/11 : RUN echo "Africa/Johannesburg" > /etc/timezone
VERBOSE:  ---> Running in 1b845c76875d
VERBOSE:  ---> 72a1eeb38fcc
VERBOSE: Removing intermediate container 1b845c76875d
VERBOSE: Step 9/11 : RUN dpkg-reconfigure -f noninteractive tzdata
VERBOSE:  ---> Running in f3a97c280aed
VERBOSE: Current default time zone: 'Africa/Johannesburg'
VERBOSE: Local time is now:      Thu Jan 18 10:41:30 SAST 2018.
VERBOSE: Universal Time is now:  Thu Jan 18 08:41:30 UTC 2018.

Using an identical Dockerfile, but building on either aspnetcore:2.0.5-stretch or aspnetcore:2.0.5-jessie as a base, the timezone does not change:

VERBOSE: Step 8/11 : RUN echo "Africa/Johannesburg" > /etc/timezone
VERBOSE:  ---> Running in e29a2e24f6c3
VERBOSE:  ---> fd3c55ff5f73
VERBOSE: Removing intermediate container e29a2e24f6c3
VERBOSE: Step 9/11 : RUN dpkg-reconfigure -f noninteractive tzdata
VERBOSE:  ---> Running in ec2a42befdd2
VERBOSE: Current default time zone: 'Etc/UTC'
VERBOSE: Local time is now:      Mon Jan 22 12:26:23 UTC 2018.
VERBOSE: Universal Time is now:  Mon Jan 22 12:26:23 UTC 2018.

How can I get this to work?

I tried RUN timedatectl set-timezone Africa/Johannesburg which is supposed to work in Debian, but it fails.

Ettery commented 6 years ago

OK, I've solved this by installing the tzdata package prior to using it.

ENV TZ 'Africa/Johannesburg'
    RUN echo $TZ > /etc/timezone && \
    apt-get update && apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean

It seems it was there in the earlier distro, but not the latest.