Automations for managing containers from HA

from HA container i create ssh key and copy to host ,
ssh now working between HA to host without password.

I have scripts which managing dockers activities as upgrade container and basically what ever i need as part of the automation I need.

I manage to execute the script , see shell_command.yaml:

 upgrade_mosquitto: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' admin@NAS '. /share/HA/MyScripts/HA_Upgrade.sh mosquitto'

 upgrade_homeassistant: ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' admin@NAS '. /share/HA/MyScripts/HA_Upgrade.sh homeassistant'

The script simply do :
docker pull new image ,stop current one , remove it and
run the docker-compose up -d <container_name>

#!/bin/sh


container_name=$1

docker=/share/CACHEDEV1_DATA/.qpkg/container-station/bin/docker

# Getting docker-compose dir
docker_compose_dir=/share/compose_file

Upgrade ()
{
$docker-compose stop $container_name
$docker-compose rm -f $container_name
$docker-compose up -d $container_name

}


cd $docker_compose_dir

$docker-compose pull $container_name

#throw to background
Upgrade &

Note , Im running the Upgrade part in background cause
when I execute the Upgrade for HA , i need to stop the container before.

Issues:

1.Everything is working fine - it upgrading all containers expect homeassistant ,
last step for docker-compose up -d not working .
I need to make the script run in background and preform the stop ,remove old container and start it.

 ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' admin@NAS '. /share/HA/MyScripts/HA_Upgrade.sh mosquitto'

I cant use docker command as is but i had to the full path of the docker ,
so instead of simple docker-compose pull

docker=share/CACHEDEV1_DATA/.qpkg/container-station/bin/docker
cd to/docker/compose/file

$docker-compose pull $container_name

I tried adding . ./profile before executing but it doesn’t help.

Just one comment - you can use directly docker-compose up -d --build to rebuild and restart container at one shot without need of stopping and remove it.

@100lv - that saved me 2 lines for stop and remove Thanks ,

Regarding second Q,

currently i need to execute the docker command with the full path of the docker ,
so instead of simple docker-compose I need to execute with
share/CACHEDEV1_DATA/.qpkg/container-station/bin/docker-compose …
I tried adding . ./profile before executing but it doesn’t help

It’s not only about 2 lines - it reduces down of the service