Is your clock permanently stuck or does it catch up?
Permanently! When I wake the PC up from hibernate (or standby), all running containers seem to have forgotten about the time in that mode. That means for example, after a weekend of inactivity, the clock will be running late by two days. And this situation will persist until you restart docker.
Confirmed I have experienced the same behavior running Hyper-V based Docker VM. I can see this affecting a lot of people who run on laptops and sleep the computer. I have occasionally been able to restart the container to fix.
In my mind this is a critical bug, I am forced to restart docker several times during the day.
Is there a bug open for this? Still happening on .1.12.3 (build 7135). Makes docker really annoying to use on laptops (every coffee break means restarting docker?)
In my case it’s off by a few days…
$ docker run -t node date Fri Oct 21 09:51:09 UTC 2016 $ docker run -t centos date Unable to find image 'centos:latest' locally latest: Pulling from library/centos 8d30e94188e7: Pulling fs layer 8d30e94188e7: Verifying Checksum 8d30e94188e7: Download complete 8d30e94188e7: Pull complete Digest: sha256:2ae0d2c881c7123870114fb9cc7afabd1e31f9888dac8286884f6cf59373ed9b Status: Downloaded newer image for centos:latest Fri Oct 21 09:52:56 UTC 2016 $ date Tue, Oct 25, 2016 6:02:56 PM $ docker run -t centos date Fri Oct 21 09:53:07 UTC 2016 $ date Tue, Oct 25, 2016 6:03:04 PM $ docker run -t node date Fri Oct 21 09:53:17 UTC 2016 $ date Tue, Oct 25, 2016 6:03:11 PM
we can set the date of MobyLinuxVM manually using How can I SSH into the Beta's MobyLinuxVM
docker run --net=host --ipc=host --uts=host --pid=host -it --security-opt=seccomp=unconfined --privileged --rm alpine /bin/sh / # hostname moby / # id uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video) / # date -s '2016-10-25 03:33:21' Tue Oct 25 03:33:21 UTC 2016 / # date Tue Oct 25 03:33:23 UTC 2016 / #
then if we check again from a docker container:
$ docker run -t node date Tue Oct 25 03:36:44 UTC 2016 $ date -u Tue, Oct 25, 2016 3:36:49 PM
so I used the following command from cygwin to quickly sync the time of the MobyLinuxVM with the windows host:
$ docker run --net=host --ipc=host --uts=host --pid=host --security-opt=seccomp=unconfined --privileged --rm alpine date -s "`date -u '+%Y-%m-%d %H:%M:%S'`" Tue Oct 25 15:49:57 UTC 2016 # check the time again $ docker run -t node date '+%Y-%m-%d %H:%M:%S'; date -u '+%Y-%m-%d %H:%M:%S' 2016-10-25 15:50:36 2016-10-25 15:50:37
Any update on this? I have to restart docker every morning to get the time correct.
I’m using @cristualexandru solution to update the time in the container every time I unlock my computer.
Prerequisites (There should be a possibility for most operating systems):
- Windows 10 (or a possibility to start a command at login)
- Installed “bash” (Cygwin or similar) environment installed
Create a file “docker-sync-time.bat” with the following content:
echo Syncing docker container time…
bash -c “docker run --net=host --ipc=host --uts=host --pid=host --security-opt=seccomp=unconfined --privileged --rm alpine date -s “$(date -u ‘+%%Y-%%m-%%d %%H:%%M:%%S’)””
Start “Task Scheduler”
Add a task (“Task Scheduler Library” -> “Create New Task…”) that starts the batch script every time you login
I use ntp with all my other hyper-v VMs. But, if the time offset is more than 1000s (which always happens after a resume) then ntp refuses to sync the time. But, adding “tinker panic 0” to /etc/ntp.conf allows ntp sync with any offset. I am not sure what the security implications are for this, but it seams to work fine for me. I would suggest including ntp in the Moby VM image with “tinker panic 0”
A quick fix for those who need to restart Docker for Windows every single morning after sleep is:
docker run -it --pid host --privileged --rm debian nsenter -i -m -n -t 1 service ntpd start``` Notice ntpd can take up to 1024 seconds in order to update a container out of sync. Best regards, Rúben
I get this error when executing “get-vm | set-vm -automaticstopaction save”
set-vm : "MobyLinuxVM": Fehler beim Ändern der Einstellungen.
Unerwarteter Fehler: Allgemeiner Fehler (0x80041001).
“MobyLinuxVM”: Fehler beim Ändern der Einstellungen (ID des virtuellen Computers 51BAF990-F1CC-4F25-AB94-A3B7E4B5896C).
MobyLinuxVM: Unerwarteter Fehler: Allgemeiner Fehler (0x80041001). (ID des virtuellen Computers:
In Zeile:1 Zeichen:10
- get-vm | set-vm -automaticstopaction save
- CategoryInfo : InvalidOperation: ( [Set-VM], VirtualizationException
- FullyQualifiedErrorId : InvalidState,Microsoft.HyperV.PowerShell.Commands.SetVM
Set-VM needs MobyLinuxVM to be off, so quit your Docker first and try again.
Note: This is not required as of Docker for Windows version 1.13
Can you guys test something like this?
@powershell $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
but looks like you can solve this going to Hyper-V manager and setting time sync:
MobyLinuxVM > Settings > Integration Services > Time synchronization
This problem is still relevant to Docker Desktop v22.214.171.124 (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.
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
I hadn’t seen the problem before v126.96.36.199. 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.
I have the same version as xakep and the same workaround worked for me. Didn’t realize it was due to a sleep issue.
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 188.8.131.52
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
I have the same issue. Do you think we could expect a fix 4 years after report ?
Running docker desktop community v184.108.40.206 stable on win10