The clock in the Hyper-V machine is in sync with the host at all times.
When the computer goes to sleep and is resumed, the Hyper-V virtual machine clock is delayed by the amount of time the computer was asleep. This causes all sort of subtle issues, e.g. I just spent several hours wondering why my OAuth credentials were working on my host machine, but failing with
invalid_grant when running from the container, and it turned out that the clock in the VM was out of sync.
Steps to reproduce the behavior
You can reproduce this bug by doing the following:
- Create a Dockerfile that just has like:
FROM node:latest CMD [ "date" ]
- Start Docker
- Run the container to verify the clock is in sync
- Send the computer to sleep
- Resume the computer a while later
- Run the container again and you’ll see less time has passed
For me, when I ran this I got output like the following (this is a Git Bash shell on Windows):
June@DESKTOP-CVHO135 ~/Documents/Projects/test $ docker build -t date:latest . Sending build context to Docker daemon 2.048 kB Step 1 : FROM node:latest ---> e79fe5711c94 Step 2 : CMD date ---> Running in fb8525d9999b ---> 34da986209f0 Removing intermediate container fb8525d9999b Successfully built 34da986209f0 SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories. June@DESKTOP-CVHO135 ~/Documents/Projects/test $ docker run date Sun Jul 10 13:01:40 UTC 2016 June@DESKTOP-CVHO135 ~/Documents/Projects/test $ docker run date Sun Jul 10 13:02:02 UTC 2016
Between running these commands, I had my computer asleep for 1 minute and 15 seconds (I timed it on my phone). Indeed you can see it in the screenshot here that the minutes no longer line up: