-
Notifications
You must be signed in to change notification settings - Fork 2k
"Timezone mismatch in .NET applications running inside Docker containers #6444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
docker run --rm -v /etc/localtime:/etc/localtime:ro -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:9.0 dotnet run
(UTC) Coordinated Universal Time
05/13/2025 01:45:58 +00:00 <<<--
docker run --rm -v /etc/localtime:/etc/localtime:ro -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:9.0 date
Tue May 13 09:46:17 CST 2025 <<<-- |
This is what I see. rich@vancouver:~/test$ cat Program.cs
Console.WriteLine(TimeZoneInfo.Local.DisplayName);
Console.WriteLine(DateTimeOffset.Now);
rich@vancouver:~/test$ cat /etc/timezone
America/Los_Angeles
rich@vancouver:~/test$ docker run --rm -v $(pwd):/app -w /app mcr.microsoft.com/dotnet/sdk:9.0-noble dotnet run
(UTC) Coordinated Universal Time
05/13/2025 01:55:17 +00:00
rich@vancouver:~/test$ docker run --rm -v $(pwd):/app -v /etc/timezone:/etc/timezone -w /app mcr.microsoft.com/dotnet/sdk:9.0-noble dotnet run
(UTC) Coordinated Universal Time
05/13/2025 01:55:33 +00:00
rich@vancouver:~/test$ docker run --rm -v $(pwd):/app -e TZ=$(cat /etc/timezone) -w /app mcr.microsoft.com/dotnet/sdk:9.0-noble dotnet run
(UTC-08:00) Pacific Time (Los Angeles)
05/12/2025 18:55:52 -07:00
rich@vancouver:~/test$ docker run --rm -v $(pwd):/app -e TZ="America/Los_Angeles" -w /app mcr.microsoft.com/dotnet/sdk:9.0-noble dotnet run
(UTC-08:00) Pacific Time (Los Angeles)
05/12/2025 18:55:43 -07:00 |
The environment variable approach works as expected. I’ve verified this in my tests. Appreciate it! @richlander |
While setting the TZ environment variable resolved the issue, I'm still curious about the root cause of the problem when this variable is not used. Would you kindly elaborate on why the timezone behaves incorrectly without explicit configuration? I appreciate your time in advance. @richlander |
Please look at dotnet/runtime#62545 (comment). To fix it, apply the suggestion dotnet/runtime#62545 (comment). |
Describe the bug
I ran a .NET program and a Go program inside a Docker container, both designed to display the current timezone. I also mounted the host's /etc/localtime into the container. Here’s the output:
Which .NET image(s) are you using?
No response
Steps to reproduce
No response
Other information
No response
Output of
docker version
Output of
docker info
The text was updated successfully, but these errors were encountered: