Sign inSign up

benyoo/ntp-server

By benyoo

•Updated over 6 years ago

Image
0

422

benyoo/ntp-server repository overview

⁠Running from Docker Hub
version: '2'
services:
  ntpserver:
    restart: always
    privileged: true
    container_name: ntp-server
    network_mode: "host"
    image: benyoo/ntp-server:3.5
    volumes:
    - /etc/localtime:/etc/localtime:ro
    cap_add:
      - SYS_NICE
      - SYS_RESOURCE
      - SYS_TIME
    environment:
    - NTP_SERVERS="time1.google.com,time2.google.com,time3.google.com,time4.google.com,hk.pool.ntp.org,asia.pool.ntp.org"

⁠Configure NTP Servers

By default, this container uses CloudFlare's time server (time.cloudflare.com). If you'd like to use one or more different NTP server(s), you can pass this container an NTP_SERVERS environment variable. This can be done by updating the vars⁠, docker-compose.yml⁠ files or manually passing --env=NTP_SERVERS="..." to docker run.

Below are some examples of how to configure common NTP Servers.

Do note, to configure more than one server, you must use a comma delimited list WITHOUT spaces.

# (default) cloudflare
NTP_SERVERS="time.cloudflare.com"

# google
NTP_SERVERS="time1.google.com,time2.google.com,time3.google.com,time4.google.com"

# alibaba
NTP_SERVERS="ntp1.aliyun.com,ntp2.aliyun.com,ntp3.aliyun.com,ntp4.aliyun.com"

⁠Testing your NTP Container

From any machine that has ntpdate you can query your new NTP container with the follow command:

$> ntpdate -q <DOCKER_HOST_IP>

Here is a sample output from my environment:

[root@DT_Node-172_30_200_200 ~]# ntpdate -q ntp.dtops.cc
server 172.30.200.254, stratum 2, offset -0.089526, delay 0.02617
21 Mar 23:12:06 ntpdate[15299]: adjust time server 172.30.200.254 offset -0.089526 sec

If you see a message, like the following, it's likely the clock is not yet synchronized. You should see this go away if you wait a bit longer and query again.

$> ntpdate -q ntp.dtops.cc
server 172.30.200.254, stratum 16, offset 0.005689, delay 0.02837
21 Mar 23:12:06 ntpdate[15299]: no server suitable for synchronization found

To see details on the ntp status of your container, you can check with the command below on your docker host:

[root@DT_Node-172_30_200_254 ~]# docker exec ntp-server chronyc tracking
Reference ID    : D8EF2308 (time3.google.com)
Stratum         : 2
Ref time (UTC)  : Sat Mar 21 15:07:14 2020
System time     : 0.000000000 seconds fast of NTP time
Last offset     : -0.000224259 seconds
RMS offset      : 0.000224259 seconds
Frequency       : 73.983 ppm slow
Residual freq   : -0.000 ppm
Skew            : 599.606 ppm
Root delay      : 0.014273214 seconds
Root dispersion : 0.030987557 seconds
Update interval : 0.0 seconds
Leap status     : Normal

Here is how you can see a peer list to verify the state of each ntp source configured:

[root@DT_Node-172_30_200_254 ~]# docker exec ntp-server chronyc sources -v
210 Number of sources = 6

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^x time1.google.com              1   6   377    15   -361ms[ -361ms] +/- 7266us
^- time2.google.com              1   6   377    18   -350ms[ -350ms] +/- 7062us
^* time3.google.com              1   6   377    18   -349ms[ +154ms] +/- 7483us
^? time4.google.com              0   6     0     -     +0ns[   +0ns] +/-    0ns
^- time.cloudflare.com           3   6   377    18   -351ms[ -351ms] +/-   44ms
^- 202-65-114-202.jogja.cit>     2   6   377    17   -358ms[ -358ms] +/-   58ms

Finally, if you'd like to see statistics about the collected measurements of each ntp source configured:

[root@DT_Node-172_30_200_254 ~]# docker exec ntp-server chronyc sourcestats -v
210 Number of sources = 6
                             .- Number of sample points in measurement set.
                            /    .- Number of residual runs with same sign.
                           |    /    .- Length of measurement set (time).
                           |   |    /      .- Est. clock freq error (ppm).
                           |   |   |      /           .- Est. error in freq.
                           |   |   |     |           /         .- Est. offset.
                           |   |   |     |          |          |   On the -.
                           |   |   |     |          |          |   samples. \
                           |   |   |     |          |          |             |
Name/IP Address            NP  NR  Span  Frequency  Freq Skew  Offset  Std Dev
==============================================================================
time1.google.com            6   3   327  +9135.696  10296.470   -162ms   381ms
time2.google.com           13   6   592  +8387.605   1227.196   -267ms   228ms
time3.google.com            6   3   326  +9844.589  13125.901    +68ms   423ms
time4.google.com            0   0     0     +0.000   2000.000     +0ns  4000ms
time.cloudflare.com         8   4   457  +8473.946   5689.502   -152ms   444ms
202-65-114-202.jogja.cit>   6   3   327 +10146.226  16692.281   +302ms   393ms

Tag summary

Content type

Image

Digest

Size

2.8 MB

Last updated

over 6 years ago

docker pull benyoo/ntp-server