To force German localization, I set TZ=Europe/Berlin
and LANG=de_DE.UTF-8
in my docker-compose.yml
file. I verified the culture by printing it in my _Layout.cshtml
file
@System.Globalization.CultureInfo.CurrentCulture.Name
This works on the default 2.1 image. Now I migrated to the alpine image to reduce size and attack surface. Now DateTime
objects behave strange: CurrentCulture.Name
gaves de-DE
when forcing them in DI and the current thread. But I still have US time format, for example /
instead of .
as delimiter. CurrentCulture.DateTimeFormat.DateSeparator
also prints /
, even it's a de
culture which should have a dot.
I could verify this by removing any localization code from Startup.cs
. Now there is no call to app.UseRequestLocalization
or CultureInfo.DefaultThreadCurrentCulture
. The Dockerfile used for building:
FROM mcr.microsoft.com/dotnet/core/sdk:2.1-alpine AS sdk-image
WORKDIR /app/MyApp
COPY MyApp.csproj .
# Copied by Jenkins since nuget.config must be on solution level for Visual Studio to work, not project level
COPY nuget.config .
RUN dotnet restore --configfile nuget.config
COPY . .
RUN dotnet publish -c Debug -o /publish
# In the alpine image, the localization from TZ/LANG env variables seems ignored
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime-image
COPY --from=sdk-image /publish .
ARG ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_URLS=http://0.0.0.0:5000
ENV ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT}
ENTRYPOINT ["dotnet", "MyApp.dll"]
This Dockerfile works fine. Now lets replace
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime-image
with
FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-alpine AS runtime-image
and the described behavior occurs: CurrentCulture
is de
but with /
instead of .
delimiter.
Why does this happen in the alpine image and how could it be fixed?
Are there some dependencies missing in alpine to let ASP.NET Core detect the localization correctly?