With the scope of testing a docker image executing a job, I would need to mock a container date during its execution, in order to do some accurate testing involving time.
Looking around the internet I didn't find any solution yet, just some paths that can be followed.
What I need is a way to change the system date, without having to connect manually to a shell, I'm planning to setup the tests using docker-compose, and I would like to configure the date as a configuration parameter.
Do you ever had similar experience? How did you solved?
First issue is changing the date, I've only found the date
command to do it.
I'm looking for 2 methods:
- Extend the base image and execute
date
before theentrypoint
. I don't feel to re-create an image for each container a problem, but I don't like the fact that I can't "proxy" the entrypoint, the only way I've found to execute thedate
command is to redefine the entrypoint with ansh
that execute it and then call the old entrypoint, but it have to "know" what it was, I didn't find a way to do whatever the base image is. - Use an NTP server. I'm a less-than-a-junior on this matter, but I was thinking about injecting in the network created by docker an ntp server that tells my mocked date to the other containers in its network. But I didn't find a way to configure a mocked ntp server in docker with fake time.
Currently I'm stucked, also a "You can't use the NTP server because blablabla..." would be helpful, or if you have some way to do it would be also better!