When using the alpine:latest base image in Docker with .NET Core 8.0, the DateTime format may not work correctly.
stuyun opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
not format
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
dotnet 8.0
Anything else?
alpine:latest base image in Docker with .NET Core 8
datatime format yyyy-MM-dd HH:mm:ss -> 2024-05-22 14 Minute: 54 Minute: 00
Can you clarify exactly what you expect to see and what you actually get from the container with text, rather than screenshots. It isn't clear to me what's the expected and observed behaviours.
My guess at the cause of your issue is that the Alpine image doesn't have ICU/tzdb installed on it, so the libraries .NET depends on to do the formatting you expect are not present.
The following Alpine image should contain these additional dependencies after a basic alpine image that includes these dependencies:
mcr.microsoft.com/dotnet/runtime-deps:8.0-alpine-extra
If that isn't the case, this issue doesn't appear to be specific to ASP.NET Core and should be transferred to either dotnet/runtime or dotnet/dotnet-docker.
The problem still persists even after following the provided instructions to install ICU and tzdb in the Alpine-based Docker image.
add ----------------
RUN apk add --no-cache icu-dev tzdata
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
ENV LC_ALL=en_US.UTF-8
ENV LANG=en_US.UTF-8
https://github.com/dotnet/dotnet-docker/blob/main/samples/dotnetapp/Dockerfile.alpine-icu
https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
add
RUN apk add --no-cache
icu-data-full
icu-libs