Docker for Windows should resync VM time when computer resumes from sleep

This problem is still relevant to Docker Desktop v2.2.0.0 (42247)

When computer goes off from sleep, then datetime in all running containers is incorrect forever (until docker desktop will be restarted).

Settings > Integration Services > Time synchronization setting of Hyper-V doesn’t help (it’s enabled by default).

This is my workaround:

In Windows Task Scheduler create a new task with this trigger:

<QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Power-Troubleshooter'] and EventID=1]]</Select></Query></QueryList>

This is “Exit from sleep mode” trigger.

And in task command select Posershell.exe as a command and -ExecutionPolicy Bypass path\to\fix-docker-time-after-sleep.ps1 as an argument.

Where fix-docker-time-after-sleep.ps1 is a file with content from the answer above:

$datetime = Get-Date
$dt = $datetime.ToUniversalTime().ToString('yyyy-MM-dd HH:mm:ss')
docker run --net=host --ipc=host --uts=host --pid=host --security-opt=seccomp=unconfined --privileged --rm alpine date -s $dt
1 Like

I hadn’t seen the problem before v2.2.0.0. I assume it’s a regression

Thanks for the script, I’ve been fixing it with the GUI. But as the new file sharing is also broken, I think I’m just going to downgrade.

Bruce

1 Like

I have the same version as xakep and the same workaround worked for me. Didn’t realize it was due to a sleep issue.

Thanks @xakep!

just adding that i am on Windows 10 with Docker for Windows.

I can confirm that each day I go home from work and come back, the clock in the linux containers has frozen at the point the computer went to sleep, and only continues once awoken.

The “quick fix” is to restart via the Docker Desktop agent, and the clocks are re-sycned.

However, I really ought not to need to do this everytime

how I noticed was because AWS S3 API requires a synced clock for some reason to download files off of it. And if it’s off by a minute, im hooped. And for some reason trying to force my linxu containers to re-sync their time with ntpd doesn’t seem to do anything but stick to the out-of-date clock its been at

Hacky workaround/fix that kicks host:docker time sync to work again by enable/disableing https://github.com/docker/for-win/issues/4526#issuecomment-539647660 and then run that on every resume/wake. https://sumtips.com/how-to/run-program-windows-wakes-up-sleep-hibernate/

Resyncs the host:docker clocks every time you open the lid of the laptop.

Same for me, was working right before 2.2.0.0
Now If docker is started and windows 10 goes in hibernate mode, after wakup, all container that are started are using date/time of the hibernate.

After a restart of docker the date time is again sync.

e.g. docker was started yesterday (11 Feb 2020) then windows 10 was in hibernate for the night and display date/time for yesterday:

docker run --rm alpine date
Tue Feb 11 05:31:32 UTC 2020

Then I restarted docker and date time is now correct:

docker run --rm alpine date
Wed Feb 12 10:47:51 UTC 2020

2 Likes

I have the same issue. Do you think we could expect a fix 4 years after report ?

Running docker desktop community v2.2.0.3 stable on win10

Using Docker for Windows, here. This used to be an issue a long time ago from me, but at some point stopped happening with an update along the way.

Last update to 2.2.04 (43472), the install failed. Second time worked but reset the Hyper-V DockerDesktopVM to a fresh vhd. After which the time was hosed. I validated the host VM was reporting a bad time as well as the containers.

Doing the following resolved it for me. Still waits to be seen of sleeping, restarts, etc effect it though.

In Hyper-v Manager, in the DockerDesktopVM settings -> Management -> Integration Services -> Unchecked Time Syncronization, hit Apply, then re-check and hit apply.

1 Like

This issue started appearing for me when I updated from 2.1.x to 2.2.x. It causes anything that uses time-based signatures to fail (e.g. many AWS services). Only fix I found is to reboot the VM.

1 Like

hmm this seems to be an issue for me as well.
i only noticed it from a weekend of my laptop going in and out of sleep /hibernation (and noticed it because of some AWS token issues as well).

restarting the container didn’t work, but restarting all of docker fixed it.

i tried going into hyper V and unchecking and re-checking the time sync to see if that helps.