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

前端 未结 17 1526
北恋
北恋 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:35

    If you are using boot2docker and ntp doesn't work inside the docker VM (you are behind a proxy which does not forward ntp packets) but your host is time-synced, you can run the following from your host:

    docker-machine ssh default "sudo date -u $(date -u +%m%d%H%M%Y)"
    

    This way you are sending your machine's current time (in UTC timezone) as a string to set the docker VM time using date (again in UTC timezone).

    NOTE: in Windows, inside a bash shell (from the msys git), use:

    docker-machine.exe ssh default "sudo date -u $(date -u +%m%d%H%M%Y)"
    

提交回复
热议问题