Operations 8 min read

How to Sync Time in Docker with Chrony: A Step‑by‑Step Guide

This guide explains how to use Chrony inside a Docker container to synchronize system time with NTP servers, shows how to configure custom NTP servers, check Docker and Chrony status, pull and run the NTP image, and verify time sources on both server and client sides.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Sync Time in Docker with Chrony: A Step‑by‑Step Guide

Chrony is a general implementation of the Network Time Protocol (NTP) that can synchronize the system clock with NTP servers, reference clocks such as GPS receivers, or manual input.

The Docker image used in this tutorial defaults to CloudFlare’s time server (time.cloudflare.com), but you can specify alternative NTP servers via the NTP_SERVERS environment variable. env=NTP_SERVERS="" Check the local Docker daemon status:

# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-12-02 04:34:05 CST; 12h ago
   ... (additional log lines omitted for brevity)

Pull the NTP container image:

# docker pull cturra/ntp
Using default tag: latest
latest: Pulling from cturra/ntp
59bf1c3509f3: Already exists
45b0d9aa13f5: Pull complete
7b02bd2e0aba: Pull complete
Digest: sha256:b4cf0bb0aba53b4438605ef30913f1fbf69d0f5ad5d3781ead43353cd64d5b92
Status: Downloaded newer image for cturra/ntp:latest

Verify the container is running:

# docker ps
CONTAINER ID   IMAGE          COMMAND               CREATED          STATUS                         PORTS                                 NAMES
58091922ab8d   cturra/ntp     "/bin/sh /opt/startu…"   20 seconds ago   Up 20 seconds (health: starting)   0.0.0.0:123->123/udp, :::123->123/udp   ntp

Check the NTP server’s time source inside the container (the source is Alibaba’s time server, confirming correct configuration):

# docker exec ntp chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 203.107.6.88                  2   6   377    13   +532u[s+1324u] +/-   21ms

On the client side, inspect the Chrony service status:

# systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-12-02 04:22:11 EST; 3min 27s ago
   ... (additional log lines omitted)

Modify the configuration file to use a specific NTP server:

# grep iburst /etc/chrony.conf
server 192.168.3.166 iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

Check the synchronization status after the change:

# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.3.166                 3   6   377    19   -233u[s-1027u] +/-   26ms
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerNTPtime synchronizationchrony
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.