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

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
2 Likes