ailispaw/docker-root

Time Syncing

Closed this issue · 13 comments

Since our Docker Root is running through Xhyve (I imagine this is the same no matter what VM middleware), when the Mac sleeps, Docker Root looses time.

This is making API calls fail. While I can manually update the time, is there a way would you suggest to keep time synced automatically?

FYI, I have currently made our team a script to sync on demand (for docker-root-xhyve):

#!/bin/bash

IP=$(cd ~/src/docker-root-xhyve && make ip 2>/dev/null)
FMT="%Y-%m-%d %H:%M:%S"
NOW=$(date -u +"${FMT}")

ssh $IP "sudo date +\"${FMT}\" --set=\"$NOW\""

@if-kenn Thank you for opening an issue.

I believe middleware has responsibility to provide a way to sync time.
I use sntp -4sSc pool.ntp.org to sync time manually like you.

With Vagrant we can set the script in Vagrantfile to do it.
https://github.com/ailispaw/docker-root-packer/blob/master/Vagrantfile#L36-L38

With docker-root-xhyve, you can use just make ssh -- sudo sntp -4sSc pool.ntp.org.

You may want to use cron to do it automatically, but I think it's not good enough.
https://github.com/ailispaw/vagrant-docker/blob/dev/Vagrantfile#L105-L106
And we can not use it frequently because of the TOS.
http://www.pool.ntp.org/tos.html

It looks like we could do it to the Mac's IP, that way we are just piggybacking off of the Mac's NTP that is already going:

sudo sntp -4sSc 10.0.0.5

Oh!! Good idea.
In xhyve instance, sudo sntp -4sSc 192.168.64.1.

I will consider how to use this automatically within DockerRoot.
Thank you so much!!

As always, glad to help and happy for such quick feedback!

@if-kenn
I'm going to put * * * * * /usr/bin/sntp -4sSc 192.168.64.1 in the root crontab to sync every minutes at docker-root-xhyve only.
It might be too frequent.
Is this OK just for xhyve local environment?
What do you think?

Before you posted this I put 15/* in the crontab, I think every minute is too much, but maybe 5/* would be a good compromise.

Thank you for your suggestion. I will do it.

Oh, I will keep it open for other hypervisors.