Troubleshooting
Node-RED in Docker uses the host clock, not its own time
Short answer
A Docker container does not keep its own clock: it reads the host Linux kernel's system time. Set the time inside Node-RED's container and you change the controller clock, not a container clock. Compare date -u on host and container, correct the controller's time synchronization, then check the timestamp field feeding the chart.
On this page
- Why does the Node-RED chart show a line instead of a time series?
- Does a Docker container keep its own clock?
- How do I compare the host clock and the container clock?
- Why did setting the time in PLCnext Engineer not change Node-RED's time?
- Why not just run date -s inside the container?
- Which timestamp is the chart actually plotting?
- How do I verify the fix after a restart?
- Questions asked
The chart draws as a line because its time axis never advances, and the time never advances because the container has no clock of its own: a Docker container reads the host Linux kernel's system time. Setting the clock from PLCnext Engineer failed because that transfer never wrote the controller's operating system clock. Compare date -u on the host and inside the container, correct the controller's time source at the layer that actually writes that clock, then trace which timestamp field the flow feeds the chart.
Why does the Node-RED chart show a line instead of a time series? #
A Node-RED chart draws a line instead of a time series when every point lands on the same or a non-advancing x-coordinate, which happens when the timestamp feeding the x-axis is missing, constant, unparseable, or hours off from the process value.
A changing y-value proves the OPC UA subscription works; it proves nothing about the time axis. The identical flow plotting correctly on the Windows PC is the useful clue: flow logic, node configuration and payload shape stayed the same, so the fault travels with the runtime environment — the clock that environment reads, or the timestamp handling it applies. Treat it as two faults to rule out in order: first the clock the container reads, then the timestamp value the chart receives as its x-coordinate. Node-RED 1.2.6 in the container is not the differentiator, because the same code passed on the PC.
Does a Docker container keep its own clock? #
No: an ordinary Docker container has no private clock or hardware timer, so it reads the host kernel's system time, and only the container's timezone setting can make the displayed local time differ while the underlying UTC time stays identical to the host.
Everything in the container — Node-RED, the OPC UA client, the chart — formats that one shared clock through its own locale, its /etc/localtime file and its TZ environment setting, fixed when the image is built or the container starts. That is why container time so often looks different from the host while UTC is unchanged. A container's own filesystem, process table and hostname do not give it a time source of its own. How Node-RED sits on the controller — as a host process or in a container — is a deployment choice, and the walkthrough of Node-RED on PLCnext in host or container mode covers what each layout shares.
How do I compare the host clock and the container clock? #
Open a controller shell and run date -u, then run the same command inside the container, and read only the UTC result: two identical readings prove the container shares the host clock and move the fault to timezone formatting or the flow.
For the container side, exec in by the container's real name — for example docker exec -it nodered date -u, with nodered standing in for this deployment's container name — and put the two UTC lines side by side. Ignore the local-time fields entirely: a local display that differs by a zone offset is expected and says nothing about the clock, the same distinction behind a historian that shows a real value hours off on its UTC offset.
Decide from the difference:
- Both readings show the same wrong UTC time: the container faithfully reports a wrong host clock, so correct the controller's time source and leave the container alone.
- Both readings show the same correct UTC time but the chart still plots wrong: the clock is solved; move to the timestamp the x-axis actually receives.
- The readings differ: ordinary Docker cannot produce that, so confirm the shell is really inside the intended container and review the runtime configuration before touching any clock.
Worked example. At 12:14:05 local time in the UTC+1 zone, both commands print Tue Dec 15 11:14:05 UTC 2020: a difference of 0 seconds, which confirms the shared clock. The chart labels read 12:14:05 — exactly 3,600 seconds ahead of the UTC reading, because 11:14:05 + 3,600 s = 12:14:05, the offset for UTC+1. That arithmetic clears the clock completely: the plotted moment is correct and only the display conversion is local, so the fix belongs to the x-axis value, not to any time setting on the controller. A container line printing 10:14:05 UTC against a host line at 11:14:05 UTC would be a 3,600-second gap of the other kind: proof you were not reading the shared kernel clock at all.
Why did setting the time in PLCnext Engineer not change Node-RED's time? #
The time transfer from the engineering tool did not reach Node-RED because it never wrote the controller's operating system clock: unless a configuration change updates the Linux system time the kernel hands to every container, the container and the flow keep reading the old value.
The test that matters is the kernel clock: if date -u on the host still prints the old time after the change, the change never reached the operating system clock, and no container can show anything different. Correct the time where the controller actually maintains it — the controller's own time-source configuration, the settings that select NTP time synchronization or perform a manual clock set — so the kernel clock moves, then repeat the two UTC readings from the comparison above to watch both lines move together. A clock that only an interactive set ever corrects is still misconfigured: without a maintained source it drifts again, and every log entry, certificate check and scheduled task on the controller inherits that drift.
Why not just run date -s inside the container? #
Do not fix this by setting the time inside the container: a command such as date -s "15 DEC 2020 11:14:00" writes the shared host clock when it is permitted at all, so it changes every process on the controller and drifts again while the clock source stays unsynchronized.
Setting the system clock is a privileged kernel operation, and container runtimes do not grant that capability by default, so the command is usually refused outright. When it does succeed, it does not create a container clock; it steps the controller's clock for every service on it at once. One caution: never step a running controller's clock by hand as a substitute for configuring its time source, because the jump reorders logs and can disturb time-sensitive services. The damage from a wrong clock reaches further than charts anyway — certificate-based connections fail against a clock hours off, the failure mode behind why a PLC ping works but AWS MQTT fails when the clock is wrong.
Which timestamp is the chart actually plotting? #
Open the debug sidebar at the OPC UA input and again just before the chart, and decide which field carries the x-axis time: the OPC UA SourceTimestamp applied by the data source, the ServerTimestamp of receipt, or a timestamp the flow generates itself.
The OPC UA specification defines the source timestamp as the stamp the data source applied to the value, so it marks when the PLC produced the reading; the server timestamp marks when the server handled it. A Node-RED flow can also stamp each message on arrival, and the chart then plots whatever time coordinate the message supplies. Those are different moments, and a fresh arrival stamp makes a chart advance even while a stale source timestamp does not — handy for debugging, but it silently changes the plotted meaning from acquisition time to receipt time, the distinction behind why a PI value timestamp is not a receipt time.
Check the representation as well as the field: epoch milliseconds, a Date object and a formatted string are not interchangeable, and two consecutive samples must show x-values that advance by the publish interval, not by zero. If the UTC readings agree everywhere but the labels sit hours off, the zone offset is the remaining suspect. The rule generalizes beyond Node-RED: a chart x-axis fed an unparseable or wrongly typed timestamp breaks the same way, which is what the time-series chart x-axis timestamp parse fix walks through.
How do I verify the fix after a restart? #
Restart the container and repeat the whole check, because a change made in an interactive shell or a test flow disappears with that session: the UTC readings must agree again, and two consecutive chart points must land 2,000 milliseconds apart when the subscription delivers a value every two seconds.
A persistent correction survives a container restart and a controller reboot; a change made only in a shell session does not. Confirm the process value itself still changes, because a correct timestamp cannot animate a constant signal — a flat y-series draws as a line even with a perfect time axis. To check the ordering of events around the fix, pull only the recent container log: Docker's log command accepts an RFC 3339 date, a UNIX timestamp or a Go duration for its since filter, so the entries just before and just after the change isolate cleanly. Host and container UTC lines matching, x-values advancing by the publish interval, both holding through a restart — that closes the fault.
Questions asked
Which privilege does setting the clock inside a container need?
Setting the system clock is a kernel capability, not an ordinary user permission: the container needs the Linux CAP_SYS_TIME capability, which container runtimes do not grant by default. If the set is refused, nothing changes; if it is granted, the command writes the shared host clock. Neither outcome creates a container-only time fix, so the clock is corrected at the controller, never inside the container.
Does the Node-RED chart pick up the OPC UA source timestamp automatically?
No. The chart plots whatever time coordinate the flow hands it: the OPC UA SourceTimestamp, the server receipt timestamp, or a stamp a function node generates on arrival. Inspect one message at the chart input, decide which field you rely on, and convert it to epoch milliseconds or a Date object before it reaches the x-axis.
Can a timezone setting alone put chart points hours off?
A timezone setting moves the printed labels, not the points, when the plotted values are proper dates. Points land hours off when a timestamp string is parsed with the wrong offset or read as local time instead of UTC. Fix that where the string is converted, not in the clock and not inside the container.
What is an OPC UA SourceTimestamp?
It is the timestamp the OPC UA specification attaches to a variable's value to reflect when the data source produced it, not when the server received or delivered it. It travels with the value as metadata, so a subscription can deliver a reading together with the stamp from the moment the PLC wrote it.
Why did the identical flow plot correctly on the Windows PC?
The Windows install read a correctly synchronized desktop clock, so the receipt timestamps the flow generated advanced normally and the chart had a moving x-axis. The container on the controller inherited a clock that the time transfer never corrected. The difference was the environment's clock, not the flow logic or the node versions.