We have several backend web services which should have time synced between them. Is the time synced between docker containers automatically or should we take care of it ourself?
The answer depends on what you mean by “having time synced”.
If you mean that you’d like to ensure your containers are in the same timezone (i.e. running
date should return the same timezone everywhere), then you need to ensure whatever source to use to derive the timezone is the same across all containers. Typically, this means at least ensuring that the
/etc/localtime file and the
TZ environment variable are the same everywhere, but your app or framework might be configured otherwise.
However, if you meant that the containers should have synced clocks (i.e. running
date -u should return the same thing on both containers), then you don’t need to do anything. The clock for the container is the system clock, and we sync the clocks on all our servers via NTP.
To be clear, NTP isn’t perfect (clocks can still drift a little bit), but there’s nothing that can be done to fix this short of running your app on specialized hardware (i.e. you can depend on time being roughly similar on all instances, but don’t expect it to be perfectly identical at al times).