For device testing a client needed a solution to set devices reliably to a time in the future to trigger certificate renewal and similar processes.
We agreed that providing a mock time via a NTP service would be a good solution. One requirement was to have the NTP service run in a Docker container.
I explored the space of NTP services and if in one of those the time could be set freely but didn’t have any luck finding such a solution. What i found was that for some NTP services the local time could be used as time source. But as we wanted to run the NTP server in a Docker container changing the local time was not possible.
After considering different approaches i came up with the following solution:
- use the NTP service chrony as it has a simple configuration and works with Docker
- for computers without network connectivity chrony can use the local time as time source and appear synchronized
- use libfaketime to deliver freely settable local time to single processes without changing the local time. For newly started programs libfaketime is loaded via library preloading and answers the system calls of those programs with fake time.
I put it all together and put my solution for running a NTP service with fake time as Docker container on github.