for-win icon indicating copy to clipboard operation
for-win copied to clipboard

Time sync differences between docker containers for Windows and the hosting machine

Open tmarinov opened this issue 7 years ago • 19 comments

DiagnosticsID: 1F3FB75F-3F5E-4EE0-8D08-4F7C2E233988/20190102225357

The following issue looks like this one: #409 but there it is written/confirmed that it is fixed with the new (back then, 2017) version, while I am having the problem now, with the latest versions. I started having an error when try to access CosmosDB from an api, contained in a Docker container hosted on my windows 10 (used to work before):

The authorization token is not valid at the current time. Please create another token and retry (token start time: Thu, 03 Jan 2019 01:47:43 GMT, token expiry time: Thu, 03 Jan 2019 02:02:43 GMT, current server time: Wed, 02 Jan 2019 22:48:57 GMT). ActivityId: d5c7cf80-1465-4abb-9dd8-a22c6b8b35a9, Microsoft.Azure.Documents.Common/2.1.0.0, Windows/10.0.17134 documentdb-netcore-sdk/2.2.0

I see a few hours time difference between the docker container and my windows 10 laptop. Here is my "anonymized" docker file:

`FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80

FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY Services//.API.csproj Services/.API/ COPY Services/****.csproj Services// RUN dotnet restore Services/.API.csproj COPY . . WORKDIR /src/Services/******** RUN dotnet build *****.csproj -c Release -o /app FROM build AS publish RUN dotnet publish .API.csproj -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", ".API.dll"] `

Started having this with image for 2.1 dotnet core. Since then:

  • restarted Docker for Windows (Version 2.0.0.0-win81 (29211); Channel: stable; Build: 4271b9e)
  • recreated the images/containers
  • Re-set Docker for Windows
  • Upgraded whole solution + images to dotnet core 2.2.

Without any success - still getting the same error.

Any ideas? (The solution contains 4 containers in total, all of them are with the same time, but it is different from the host machine (my windows laptop. Same solution was working about 1 month ago - before Docker and Windows upgraded)

Update If I do: docker exec -it de7 cmd and then: C:\app> Time I am getting: The current time is: 3:15:18.44 which is 8 hours different than my hosting machine's current time.

But if I make a new file in the container: C:\app> echo abc > MyFile.txt

I am getting the correct creation time: 01/02/2019 11:12 PM myfile.txt

tmarinov avatar Jan 02 '19 18:01 tmarinov

Install ntp on the container?

Sieabah avatar Jan 14 '19 06:01 Sieabah

I am having this issue as well, using aspnet:latest

TimZander avatar Jan 29 '19 20:01 TimZander

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale comment. Stale issues will be closed after an additional 30d of inactivity.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle stale

docker-robott avatar Apr 29 '19 01:04 docker-robott

/remove-lifecyclestale

denissa4 avatar May 27 '19 16:05 denissa4

Has anyone come up with any solution to this problem? I ran into the same issue right now when trying to access CosmosDb container from a container using mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1803 as base. Time difference is 8 hours for me also. When accessing the CosmosDb container from the host then I had no issues.

JohanOhlin avatar Jul 01 '19 20:07 JohanOhlin

Probably will need to install ntp so you're not relying on the docker clock

Sieabah avatar Jul 04 '19 02:07 Sieabah

I managed to solve it in the end by upgrading to the latest Windows 10 version (10.0.18362) and was then also able to upgrade my container to use mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-1903 (compared to 1803 before). No more time problems causing certificate issues :-)

JohanOhlin avatar Jul 04 '19 06:07 JohanOhlin

As another datapoint, Im getting some ~similar behaviour:

edit: added windows context:

Microsoft Windows [Version 10.0.18362.145]
ethan@host:~$ echo "container: $(sudo docker run alpine date)" && echo "host:      $(TZ="UTC" date)"
container: Wed Jan 15 03:41:01 UTC 2020
host:      Wed Jan 15 20:06:12 UTC 2020

ethan@host:~$ sudo docker version
Client:
 Version:           18.09.7
 API version:       1.39
 Go version:        go1.10.1
 Git commit:        2d0083d
 Built:             Fri Aug 16 14:20:06 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:29:19 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

coip avatar Jan 15 '20 19:01 coip

/remove-lifecycle stale

coip avatar Jan 15 '20 20:01 coip

What I've done is simply restart the Docker environment and the sync was correctly done in the container.

nate-vukovich avatar Jan 27 '20 19:01 nate-vukovich

I'm also seeing this behaviour after upgrading to Docker Desktop 2.2.

Mikk36 avatar Jan 27 '20 21:01 Mikk36

What I've done is simply restart the Docker environment and the sync was correctly done in the container.

the restart is simple, knowing to expect telemetry submissions (etc, insert artibrary timesensitive processing here) arriving ~half a day off is the less simple/obvious complication here... 😅

coip avatar Jan 27 '20 22:01 coip

Possibly the same as #4526 (I experienced it as API auth problems too!)

jimjam-slam avatar Jan 28 '20 22:01 jimjam-slam

As the person who opened #4526, I'm comfortable closing that one in favor of this one, or whichever issue is most informative at this point. There's a lot of chiming in on both.

I would have probably discovered this issue before opening mine if it had linked to #72.

davclark avatar Jan 29 '20 15:01 davclark

My computer datetime is "02/14/2020 02:50 PM". if run tag ":1803" image will get incorrect datetime.

  1. docker run -it --rm mcr.microsoft.com/windows/nanoserver:1803 cmd.exe
C:\>date /t
Sat 02/15/2020

C:\>time /t
06:51 AM
  1. docker run -it --rm mcr.microsoft.com/windows/servercore:1803 cmd.exe
C:\>date /t
Sat 02/15/2020

C:\>time /t
06:53 AM

If run tag ":1909" datetime is correct.

  1. docker run -it --rm mcr.microsoft.com/windows/nanoserver:1909 cmd.exe
C:\>date /t
Fri 02/14/2020

C:\>time /t
02:50 PM

docker version

C:\>docker version
Client: Docker Engine - Community
 Version:           19.03.5
 API version:       1.40
 Go version:        go1.12.12
 Git commit:        633a0ea
 Built:             Wed Nov 13 07:22:37 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.5
  API version:      1.40 (minimum version 1.24)
  Go version:       go1.12.12
  Git commit:       633a0ea
  Built:            Wed Nov 13 07:36:50 2019
  OS/Arch:          windows/amd64
  Experimental:     false

win ver:

C:\>ver

Microsoft Windows [版本 10.0.18363.592]

kkbruce avatar Feb 14 '20 06:02 kkbruce

Having the same issue with mcr.microsoft.com/dotnet/framework/aspnet:4.7.2 on Windows 10 (1903), containers consistently created with OS time two or more hours ahead of host. Restarting services/host provides no relief.

I believe this was introduced with the docker desktop update as my image has changed only superficially in the last few months and this issue presentation appears to have surfaced after the docker desktop update. I did experience this issue around a year ago, and a Docker Desktop update apparently resolved it.
EDIT: On another windows 10 (1903) machine I loaded up Docker Desktop 2.1 and ran the same image as above, and the container time matched the host. I'm in the process of downgrading my main development laptop from 2.2 to 2.1 to see if this resolves the problem.

liberdis avatar Feb 18 '20 14:02 liberdis

In release note: https://docs.docker.com/docker-for-windows/release-notes/#docker-desktop-community-2203 Known issues: In some cases, Docker containers do not synchronize time with the host when the host machine is put to sleep.

philippe-granet avatar Mar 06 '20 08:03 philippe-granet

This is the same as #4526, and there's more discussion there, so I'm going to close this copy.

There is a new build at https://github.com/docker/for-win/issues/4526#issuecomment-600688253 that you can try.

stephen-turner avatar Mar 23 '20 14:03 stephen-turner

Closed issues are locked after 30 days of inactivity. This helps our team focus on active issues.

If you have found a problem that seems similar to this, please open a new issue.

Send feedback to Docker Community Slack channels #docker-for-mac or #docker-for-windows. /lifecycle locked

docker-robott avatar Jul 04 '20 03:07 docker-robott