New to docker and have a switch that does not want to work

I just moved to docker and Ubuntu from my Pi3. I have a UPS that I want to run a test on from time to time, it is directly connected to the hassio host via usb and running Nut. All of that is working well.

The issue is that I need to issue the following commands to start and stop the test:

drups_test_deep:
        command_on: docker exec addon_40817795_nut upscmd -u nut -p pm9600,sa drups test.battery.start.deep
        command_off: docker exec addon_40817795_nut upscmd -u nut -p pm9600,sa drups test.battery.stop
        friendly_name: drups load test  

I am running the addon SSH & Web Terminal. From the provided integrated terminal the above commands work with protection mode off. But, if I drop into the homeassistant docker container with the Portainer shell and run the commands I get:

bash: docker: command not found

This is the error that appears in the logs when I try to issue the commands as a command line switch:

Command failed: docker exec addon_40817795_nut upscmd -u nut -p pm9600,sa drups test.battery.start.deep

So, it appears to me that the homeassistant container cannot make a direct connection to the underlying docker system to make the call.

How do I get around this? Am I going to have to SSH to something and then issue the commands?

Did you try putting the commands in quotes like this:

drups_test_deep:
  command_on: "docker exec addon_40817795_nut upscmd -u nut -p pm9600,sa drups test.battery.start.deep"
  command_off: "docker exec addon_40817795_nut upscmd -u nut -p pm9600,sa drups test.battery.stop"
  friendly_name: drups load test

I have tried ', " and none. Same results.

If you are in docker, the command gets issued in the docker container shell and not on the host. You need to ssh into the host and then issue the command.

One way is to install sshpass in your docker Home Assistant container. You can try this by first ssh into the container with

sudo docker exec -it  home-assistant /bin/bash

If this gets you into the container shell, I can show you how to do the rest.

So… I need to ssh into the linux system from home assistant the issue the command, not into another container.

Thats correct. Try the command I posted and see if you get a bash-5.0# prompt

Ok, so it works from the terminal window within home assistant if I have protection off in the addon SSH & Web Terminal. If protection is on I get the long message in the window telling me that protection is on and I can’t access other containers. If I drop into the container shell in portainer it does not see the docker command.

Good, you are using portainer, so this makes it easier. Just issue the following command inside the container shell:

apk add sshpass

inside the home assistant container shell?

Yes. I actually had the same problem today and I just fixed it :slight_smile:

Ok, done. What next?

Now, try to ssh into your host fro mthe container shell:

sshpass -p 'your_host_password'  ssh your_host_username@your_host_ip_address

You need to put the password inside the quotes

The main Ubuntu shell is at 192.168.1.6:2222 and I get a dns error if I try to use the correct port number.

ok, try -p 2222 instead, like

ssh username@your_host_ip -p 2222

sshpass -p xxxx ssh [email protected] -p 2222

It gives me back the same prompt. I was trying 192.168.1.6:2222, way wrong. See above

Ok, might be a route or firewall issue. I am using the standard 21 port. Any chance you can change the ssh port to 22?

If you solve the port issue, all you need to do is to change your shell command as per below:

command_on: echo 'put your docker exec addon_40817795_nut upscmd command here inside quotes' | sshpass -p 'password' ssh username@ipaddress

and your shell command now gets executed on the host.

In order to be able to externally attach to the HA install, it wanted the addon wanted port 22. So, inorder to attach to the base os I set the base os on another port. This way I have ssh access to both.

I understand. Unfortunately, I am not good at network issues and this appears to be one