With this method, you can seamlessly interact with Docker containers running on a different machine (e.g., a virtual machine or physical server) using Home Assistant. Whether you need to start, stop, restart, or kill containers, this setup provides a simple way to control your containers using Home Assistant’s powerful automation system.
- start container
- stop container
- kill container
- restart container
-
Install the SSH Add-on:
- In Home Assistant, go to Settings → Add-ons → Add-on Store.
- Search for Terminal & SSH, install it, and start it. Enable
Start on bootandWatchdog.
-
Generate SSH Keys:
- Open the Terminal & SSH add-on terminal.
- Run these commands:
mkdir -p /config/.ssh ssh-keygen -t ed25519 -f /config/.ssh/id_rsa -N ""- This creates a key pair without a passphrase (to avoid prompts).
- Important: Use
/config/.ssh, not/data/.ssh. This ensures the keys persist after updates.
-
Find Your Public Key:
- In the SSH terminal, run:
cat /config/.ssh/id_rsa.pub
- Copy the output (it starts with
ssh-ed25519 ...).
- In the SSH terminal, run:
-
Add the Key to the VM (the VM where docker is installed):
-
SSH into your VM (from your local PC or HA terminal):
-
Note: You can use PuTTY to ssh to Home Assistant and the VM where Docker is installed.
ssh user@vm-ip
-
On the VM, run:
mkdir -p ~/.ssh echo "PASTE_YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
-
- Ensure the private key has strict permissions:
chmod 600 /config/.ssh/id_rsa
-
Edit the SSH config file (
/etc/ssh/sshd_config):sudo nano /etc/ssh/sshd_config
-
Add/update these lines:
PermitRootLogin no # Disable root login (Optional) PasswordAuthentication no # Disable password login PubkeyAuthentication yes # Enable SSH keys
-
Restart SSH:
sudo systemctl restart sshd
or
sudo systemctl restart ssh
- From Home Assistant’s SSH terminal, test:
ssh -i /config/.ssh/id_rsa user@vm-ip
- Replace
userandvm-ipwith your VM’s username and IP. - If it works, you’ll log in without a password. Type
exitto quit.
- Replace
This error occurs because Home Assistant doesn’t "trust" the VM’s SSH fingerprint. To fix it:
- Manually Accept the Fingerprint:
- Run this command once in the HA SSH terminal:
ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@vm-ip "exit" - This adds the VM’s fingerprint to
/root/.ssh/known_hostsin HA.
- Run this command once in the HA SSH terminal:
-
Add
shell_command:- In
configuration.yaml, add:shell_command: docker_start_container_name: 'ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@vm-ip "docker start container_name"' docker_stop_container_name: 'ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@vm-ip "docker stop container_name"' docker_kill_container_name: 'ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@vm-ip "docker kill container_name"' docker_restart_container_name: 'ssh -o StrictHostKeyChecking=no -i /config/.ssh/id_rsa user@vm-ip "docker restart container_name"'
- Replace
user,vm-ip, andcontainer_name. - This command disables host key checks and uses the correct key path. Once confirmed working, you COULD remove
-o StrictHostKeyChecking=no.
- In
-
Restart Home Assistant:
- Go to Settings → System → Restart.
- Create a Test Automation:
- Go to Settings → Automations → Create Automation.
- Use a simple trigger (e.g., time), and set the action to
Perform Action→shell_command.docker_start_container_name. - Replace
container_name. - Test it to see if the container starts.
example:
description: ""
mode: single
triggers:
- trigger: state
entity_id:
- input_boolean.adguard_toggle
from: "off"
to: "on"
conditions: []
actions:
- action: shell_command.docker_adguard_start
data: {}

