I have dockers running on Linode servers. At times, I see that the time is not right on the dockers. Currently I have changed the run script in every docker to include the following lines of code.
yum install -y ntp service ntpd stop ntpdate pool.ntp.org
What I would ideally like to do however is that the docker should sync time with the host. Is there a way to do this?
To use the docker exec command, you will need a running Docker container. If you don't already have a container, start a test container with the following docker run command: docker run -d --name container-name alpine watch "date >> /var/log/date. log"
The source for this answer is the comment to the answer at: Will docker container auto sync time with the host machine?
After looking at the answer, I realized that there is no way a clock drift will occur on the docker container. Docker uses the same clock as the host and the docker cannot change it. It means that doing an ntpdate
inside the docker does not work.
The correct thing to do is to update the host time using ntpdate
As far as syncing timezones is concerned, -v /etc/localtime:/etc/localtime:ro
works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With