How to run docker container from HA

Hi,
I’ve got some docker container. I can kill it an restart from terminal (Supervised on Debian 12) by commands:

  • sudo docker kill <container name>
  • sudo docker restart <container name>
    And everything work fine.
    Question from nub. How can I repeat the above commands from HA automation (shell command, script or what ever) to kill and restart this container?

RESOLVED
shell_command: start_detect: ssh -i /config/ssh/id_rsa -o UserKnownHostsFile=/config/ssh/known_hosts <user>@<ip address> 'sudo docker restart <container name>'

It all depends on which “flavor” (Core, Container, Supervised or HAOS) you are using

Hi. Supervised on debian.

I think you can.
Just ssh from your HA container to the host to execute your docker commands, through a shell_command

E.g.

shell_command:
  rebuild_ha: >
    ssh -4 -o ConnectTimeout=3 -o StrictHostKeyChecking=no user@ha_host.lan 'nohup sh -c "docker-compose -f /opt/docker_files/homeassistant/docker-compose.yml build --pull && docker-compose -f /opt/docker_files/homeassistant/docker-compose.yml up -d" > /dev/null 2>&1 &'