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