-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
About time incorrect of docker image about aspnet-6 #62545
Comments
I'm unable to repro this. Here are the steps I took to attempt to repro this:
Are you sure you don't have any other configuration in your Dockerfile that may be leading to this behavior? Please provide repro steps. |
when I run the container,I map the local time into it --use -v - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime |
Thanks, I can repro this now by including @mattjohnsonpint - Is this a known change in behavior for .NET 6 to not use the
Is this behavior difference documented anywhere? |
Triage: Moving this to dotnet/runtime repo to be investigated. |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Is |
Tagging subscribers to this area: @dotnet/area-system-globalization Issue DetailsHello:
|
No, not by default. It doesn't exist in the 5.0 image either but it returns the expected result in that version. |
Not sure about that from memory, but Also note the old display name was wrong. |
See also related dotnet/dotnet-docker#1366 |
Sorry about that, I was mistaken. Yes, tzdata is installed for both 5.0 and 6.0 on Debian/Ubuntu. |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsHello:
|
@mthalman @tonyjianhu could you please check if the environment variable Also, were you running .NET 5.0 and .NET 6.0 on the same container? |
Nope, there is no
No, this behavior occurs with the |
Thanks for the info. Is there a chance to install and try .NET 5.0 on this container? I don't think we changed anything between .NET 5.0 and .NET 6.0 on the way getting the local time zone. So, my guess here is somehow it is container image configuration. Sorry, I am currently on vacation, and I don't have a handy environment to quickly try it myself. Thanks! |
The only difference is the addition of an environment variable, |
Agree, I don't think logging will affect the time zones at all.
Could be. But looking at the code, I am seeing we are doing the same thing in both .NET 5.0 and .NET 6.0. We had some code refactoring in .NET 6.0, but I don't expect it will break reading local time zone file. Note, the code depends on the symbolic link of the Anyway, all what I mentioned here are guesses. Still there is a chance .NET has a regression which I am not seeing from reading the code. I'll try to take a look later when I get a chance. |
I have looked briefly at the issue, and here is what I am seeing:
running the following command:
which means the Even doing
Again, the system seeing the local time zone is Although this seems a regression in .NET 6.0, but this configuration looks not good to use as it will create confusion on such systems. You already can see the display name using .NET 5.0 showing the zone name is I suggest to you, instead of using set the default time zone using or execute commands like:
I'll keep this issue open to look more at what has changed in .NET 6.0. I'll reduce the priority of this issue as from my analysis it is not right to use such configuration and there is an easy workaround that can be used. |
This is probably a regression in .net 6.0.1 . root@1a2e2f4396ed:/# echo "Asia/Shanghai" > /etc/timezone
root@1a2e2f4396ed:/# cat /etc/timezone
Asia/Shanghai
root@1a2e2f4396ed:/# rm -rf /etc/localtime
root@1a2e2f4396ed:/# ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
root@1a2e2f4396ed:/# ls -l /etc/localtime
lrwxrwxrwx 1 root root 33 Jan 13 15:06 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
root@1a2e2f4396ed:/# date
Thu Jan 13 15:06:57 CST 2022
root@1a2e2f4396ed:/# pwsh
PowerShell 7.2.1
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /> [System.DateTime]::Now
Thursday, 13 January 2022 07:07:11 |
I have same issue. I've tried 6.0, 6.0.1-focal and bullseye but it didn't fixed. volumeMounts:
- name: tz-config
mountPath: /etc/localtime
- name: tz-config
hostPath:
path: /usr/share/zoneinfo/Europe/Istanbul It was working for .net 3 and .net 5 until upgraded to .net 6 images. So I've tried @tarekgh workaround for .net 6 images, and it seems that worked: spec:
containers:
command: #TODO: remove this command when this bug is fixed: https://github.com/dotnet/runtime/issues/62545
- /bin/sh
- -c
- |
unlink /etc/localtime
ln -s /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
dotnet MyApplication.dll I don't know why overwritten the localtime file in .net 6 image, but the hostPath mount was working before .net 6. |
It is wrong to hostPath the timezone file. I explained before in my comment #62545 (comment). The file you are mounting was symbolically linked too inside the OS. That causes confusion in general when reporting the time. In .NET 5.0 was reporting the time from one zone and reporting the zone name from a different zone (UTC). so even it looks it was working in .NET 5.0, but the behavior for sure was wrong. The .NET 6.0 is more consistent and following the OS symbolic link which results in the expected result as how the time zone is setup on such container. Please try to avoid using |
I'd like to drop a friendly reminder here that it continues to remain a best practice (IMHO) for servers (and by extension containers) to be set to UTC, and for the applications running on them to be designed such that they are time zone agnostic. If the application you're running requires the environment's time zone to be set to anything in particular, that's generally a smell that you should revisit what "local time" means in the context of your application. For .NET, some APIs that use the concept of "local time" are: As a brief example, instead of calling |
Happens also when mapping to the host's /etc/localtime. Ubuntu Example:Starting a simple new console app for both targets 5 and 6: Program.cs
tmpProj.csproj
Running Test.net 5 docker - works fine:
.net 6 docker - BAD! we see the output doesn't include the GMT+3 of the host:
|
@MichaelSimons fyi |
@meirkr as mentioned earlier in this issue it is wrong to use .NET 6.0 behavior is right as the containers internally hard linking the time zone file and always report consistent zone info. Also, .NET 5.0 was wrong as indicated before it reports wrong data (like when you request the display name of the time zone). I am closing this issue, please send any more questions if there is anything unclear here. |
We have same problem with net6.0 on the docker engine. |
But I don't need spcific TZ. I need the container to use host's TZ whatever it is, automatically. P.S |
docker run --rm -e TZ=$(cat /etc/timezone) mcr.microsoft.com/dotnet/aspnet:6.0-focal date ... but it's extremely unusual to care about host timezone at all on a server/in a container. |
When running on premise dockerized apps.... I'll try that approach, hopefully to find a docker compose solution... tx. |
The physical location of the server should be irrelevant; requiring configuration of the host's timezone is going to cause problems/confusion if you move the server. For that matter, it can cause you problems if you want to start hosting this application for people (since it would require to use a container per customer/region). Server applications should be written to use timezones and other data from relevant entities referenced during web requests. |
Hello:
I ran asp.net core application in docker container , used version of .Net 6 for mcr.microsoft.com/dotnet/aspnet:6.0-focal mirror versions. In my program, executed:
[Console.WriteLine (Datetime.Now.ToString("yyyy-MM-dd HH:mm:ss"))] ,the command output was [2021-11-26 12:58:12]. And then I entered the container and executed [date] command.The output was [Fri Nov 26 20:59:12 CST 2021].
That was almost an eight-hour difference. In.NET 5, there is no such problem.
The text was updated successfully, but these errors were encountered: