How to make sure docker's time syncs with that of the host?

前端 未结 17 1481
北恋
北恋 2020-12-02 07:10

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 f

相关标签:
17条回答
  • 2020-12-02 07:38

    I have the following in the compose file

    volumes:
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"
    

    Then all good in Gerrit docker with its replication_log set with correct timestamp.

    0 讨论(0)
  • 2020-12-02 07:38

    For docker on macOS, you can use docker-time-sync-agent. It works for me.

    0 讨论(0)
  • 2020-12-02 07:41

    Enabling Hyper-V in Windows Features solved the problem: Windows Features

    0 讨论(0)
  • 2020-12-02 07:42

    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.

    0 讨论(0)
  • 2020-12-02 07:43

    I've discovered that if your computer goes to sleep then the docker container goes out of sync.

    https://forums.docker.com/t/time-in-container-is-out-of-sync/16566

    I have made a post about it here Certificate always expires 5 days ago in Docker

    0 讨论(0)
提交回复
热议问题