En-/Disable Network Time Sync from Docker failed

Hi,

I use Torizon-OS 6.8 with Docker. Within the Container, I need to change date/time (no root). This works with setting container capabilities to CAP_SYS_TIME. But I need to en-/disable network time sync, too.
Running # timedatectl set-ntp false fails with following message:
System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down

How to solve this problem?


Software summary
------------------------------------------------------------
Bootloader:               U-Boot
Kernel version:           5.15.148-6.8.0+git.8c5c2dcbf6ba #1-TorizonCore SMP PREEMPT Tue Aug 6 10:01:59 UTC 2024
Kernel command line:      root=LABEL=otaroot rootfstype=ext4 quiet logo.nologo vt.global_cursor_default=0 plymouth.ignore-serial-consoles splash fbcon=map:3 ostree=/ostree/boot.1/torizon/769aaeaed06edb176a67c2a855ad5533655b877844acacd7ec073df66eaeaa8d/0 clk-imx8mp.mcore_booted=1
Distro name:              NAME="TorizonCore"
Distro version:           VERSION_ID=6.8.0-build.22
Distro variant:           VARIANT="Docker"
Hostname:                 verdin-imx8mp-14707144
------------------------------------------------------------

Hardware info
------------------------------------------------------------
HW model:                 Toradex Verdin iMX8M Plus on Mallow Board
Toradex version:          0058 V1.1A
Serial number:            14707144
Processor arch:           aarch64
------------------------------------------------------------

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello!

When dealing with time synchronization issues in containers on Torizon OS, there are a few important considerations:

  1. Time Synchronization in Containers: You might encounter issues with Docker’s date synchronization with the host system. This is a known issue, and more details can be found in the Torizon FAQ.

  2. Docker on Windows: If you’re using Docker on a Windows system, a common solution for time synchronization issues is to restart the Docker daemon on your host machine. This can help align the container’s time with the host system.

  3. Accessing the Hardware Clock: For managing time at the hardware level, refer to the RTC (Real-Time Clock) documentation as mentioned in the FAQ.

Regarding your specific need to disable network time synchronization from within a container, here are some suggestions:

  • Host-Level Management: It might be more effective to manage time synchronization at the host (Torizon OS) level rather than within the container itself. This ensures consistency across all containers.

  • RTC Documentation: Check the RTC documentation for additional options on time management that might suit your needs.

  • Container Privileges: If you decide to manage time at the container level, you may need to run the container with additional privileges, such as beyond just CAP_SYS_TIME, to allow for more control over time settings.

I hope this helps! If you have any more questions or need further assistance, feel free to ask.

Best regards, Toradex AI Assistant.

Greetings @Lars.ceta,

How exactly did you run the container in this case?

To do what you seek is a little tricky since it involves interacting with the host system’s systemd from with a container.

On my side I used the following docker run arguments: docker run --rm -it --privileged -v /run:/run.

I just used --privileged for simplicity, but this probably still works with more narrow permissions. The important part is the bind-mount on /run. This is where the socket files are for systemd interaction. With this I was able to successfully execute timedatectl set-ntp false. Checking the relevant systemd services on the host it seems to have worked.

As a side-note for some systemd related commands inside the container, you may have to execute them with the variable SYSTEMCTL_FORCE_BUS=1 set. This will force the command to connect to the socket despite any issues it may think is present (probably due to being inside a container). With this you can even do things like systemctl status/stop/start in a container and have it affect the host services.

Best Regards,
Jeremias