Reboot host from the docker using rtcwake command inside the container

Is there any way to power off the toradex board through rtc wake command inside from the docker container with
rtcwake -d /dev/rtc1 -m off -s 60?
There is no access of systemd from inside the container. so i am not being able to achieve my intermittent operation. I have achieved sleep mode using “rtcwake -d /dev/rtc1 -m mem-s 60” from inside the container but there was a problem and also little bit power consumption in mem mode. so i want to use “off” mode, which works perfectly when i run it from Host-level script:
Run a script on the host system that monitors for a signal from the container (e.g. via a shared volume or network communication) and executes the rtcwake command when triggered.
but i want to achieve the rtcwake off command from inside the container not from calling any host-level script. Thank you!

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

Did you like my answer?

:+1: :-1:


Based on the context provided, executing the rtcwake -d /dev/rtc1 -m off -s 60 command directly from within a Docker container is not feasible due to the inherent limitations of Docker containers. These limitations include restricted access to hardware resources and the absence of systemd, which are necessary for executing such commands.

The recommended approach is to use a host-level script that listens for a signal from the container and executes the rtcwake command when triggered. This method effectively bypasses the container’s isolation but does not meet your requirement for direct execution within the container.

While you may consider adjusting Docker’s security settings or using privileged mode to potentially allow such operations, these approaches could introduce security risks and are not guaranteed to work. Therefore, the most reliable solution remains the use of a host-level script to manage the power-off operation.

Please, also check if these links can help you solve your problem:

https://community.toradex.com/top?page=103

Correct way of switching off.

Hi @makasujan
I am not too familiar with rtcwake but what you could do is to mount all necessary binaries and libraries from the host system into the docker container. Then when you are calling rtcwake inside your container it actually calls it “outside” of the container.
But I am not a huge fan of this solution, as the AI Bot mentioned, this comes with some security issues. Most likely you need to run your container in priviledged mode and who knows what modules you need to mount into the container just to perform this task and this can open the doors for other security issues.

I did this to perform system commands at the host system from a docker container:
I created a systemd service which periodically checks for a specific file and when it discovers it, it executes a script with the command. In your case this could be the rtcwake command.
The docker container now creates this file, whenever the command needs to be executed.
With this, I only need to mount the directory which is checked by the systemd service to create the file and can run the docker container in normal user mode.
A little side note: To further increase security I stored the systemd configuration and the script to be executed in the read-only section of the file system.

Of course, you can use other trigger mechanisms instead of creating and deleting a file, but I like this simply approach.

I hope this helps you