I have some code that looks up timezones by ID like so
string tz = "Pacific Standard Time";
var timezone = TimeZoneInfo.FindSystemTimeZoneById(tz);
In my Dockerfile if I declare the image as
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS release
the code works, however if I try to switch to Alpine (even if I add the tzdata) it fails with an exception
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine3.15 AS release
RUN apk add --no-cache tzdata
Exception:
System.TimeZoneNotFoundException: The time zone ID 'Pacific Standard Time' was not found on the local computer.
---> System.IO.FileNotFoundException: Could not find file '/usr/share/zoneinfo/Pacific Standard Time'.
I think I'm missing a package or something but I'm not sure. What do I need to add to Alpine so it'll pick up Windows style timezones properly?
CodePudding user response:
The ICU library contains the mappings from the Windows time zones to IANA time zones. Also, ensure that invariant globalization is off:
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT false
RUN apk add --no-cache icu-libs tzdata