-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Describe the bug
On Alpine .NET SDK image.
Application that using Globalization Invariant Mode don't works as expected.
(Setting is overwritten by environment variable that set by Alpine image)
Which .NET image(s) are you using?
mcr.microsoft.com/dotnet/sdk:9.0-alpine3.22-amd64
Steps to reproduce
- Create
Console Applicationwith following setting
- Framework: .NET 8.0
- Enable container support: Checked
- Container OS: Linux
- Container build type: Dockerfile
- Switch to
Releaseconfiguration - Add following setting to csproj
<InvariantGlobalization>true</InvariantGlobalization>
- Add following setting to Dockerfile's
From base AS finalstage(It's required to run .NET8 app on .NET9 runtime)ENV DOTNET_ROLL_FORWARD=LatestMajor - Change base images to use
mcr.microsoft.com/dotnet/sdk:9.0-alpine3.22-amd64 - Modify Program.cs with following code.
public static void Main() { var data = new[] { "aaa", "BBB", "ccc" }; var sorted = data.OrderBy(x => x, StringComparer.InvariantCulture); foreach (var s in sorted) Console.WriteLine(s); }
- Run application on docker container
Expected result
Sorted by Ordinal orders (It's enforced by InvariantGlobalization mode)
BBB
aaa
ccc
Actual result
Sorted by InvariantCulture orders
aaa
BBB
ccc
Other information
Alpine image for .NET SDK install ICU packages and disable InvariantMode explicitly.
https://github.com/dotnet/dotnet-docker/blob/main/src/sdk/9.0/alpine3.22/amd64/Dockerfile#L30
But when enable InvariantGlobalization setting on csproj.
It's output following settings on runtimeconfig.json.
And it has a higher priority than the environment variable. (I've also confirmed actual behavior on Windows environment)
https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables?utm_source=chatgpt.com#set-invariant-mode
But it seems environment variable setting is used on Alpine image.
Because it works as expected when overwrite environment variable with following setting.
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
This issue is occurred only when using Alpine base image(.NET 9 SDK /.NET 10 SDK)
It's not happens when running on .NET 8 SDK image.
I've tested following images and it works as expected (InvariantMode is always used)
- Ubuntu 24.04
- Debian 12
- Azure Linux 3.0
Output of docker version
Server: Docker Desktop 4.45.0 (203075)
Engine:
Version: 28.3.3
API version: 1.51 (minimum version 1.24)
Go version: go1.24.5
Git commit: bea959c
Built: Fri Jul 25 11:34:00 2025Metadata
Metadata
Assignees
Labels
Type
Projects
Status