How to execute the host system command in the edge workflow(docker container)?

Hi there
Hope you are well.

I am using the edge workflow with my gateway.
So, my question is, can I execute the host system command inside the docker container?
I know there is a “run executable” node in the edge workflow, I tried to use this node, but it can execute the command of the docker container itself, it could not execute the host system command.

For example, my gateway is based on the OpenWRT OS and I can use “uci” command in the host OS terminal. As you know, uci is widely used to set and get the gateway configuration.
But, I can not execute this command inside the docker container.

How can I solve this problem? I already searched the forum a lot, and it says I need to rebuild the docker file as per my requirement. so it is not a problem to rebuild the docker image.
But, how can I add this feature to my own docker image? So how can I execute the host OS command and get its result from the edge workflow?

I am not clear to this.
Looking forward to your help.

Regards.

Hi @Abdurahman_Hojkuric and welcome to the Losant forums!

I’m taking a look at this now and will get back with you shortly.

Hi @Sebastian_Turner
Thank you for your prompt reply.

I will wait for your update.
Thanks

Running a script on the host from a Docker container is fairly involved. Here’s what I’d recommend trying first:

  1. Run the Docker container with --net=host
  2. Get the local machine’s hostname
  3. Create a user on the host machine with the necessary privileges
  4. Set an SSH config to allow that user to sign in without a password
  5. Utilize a Run Executable Node with a command like ssh myuser@hostname "uwi this-or-that"

Doing some cursory research, there are a few different approaches to this, some of which are discussed here: How to run shell script on host from docker container? - Stack Overflow

Hopefully this will help to get you on the right track. Let us know how it goes or if you have any further questions.

Hi @Sebastian_Turner
Thank you for your update.

I tried your solution, so in order to run the docker container again, I stopped the existing one and removed it, and tried to run the docker container again.
But, after re-running the docker container, it looked like the docker container works properly, but if I see the docker log, I see “Illegal instruction” and the gateway is not connected to the losant.
I am using the latest losant docker image for now, I tried this one several times. but no luck so far.

So what should I do to fix this issue? I have searched the forum a lot, and it says it is related to the old docker image, but in my case, it is not.

Looking forward to your help.
Regards,

Hi @Sebastian_Turner
Do you have any update for me?
So, at first it worked properly, but after I run the docker container next time, it does not work anymore.

I am waiting for your reply now.
Thanks.

Can you please share the docker run command that you’re using, along with the associated edge workflow?

Hi @Sebastian_Turner
Thank you for your update.

Just this one, “Illegal instruction”, nothing else.
So I have solved this problem myself, before run the docker container, I removed the DB file in losant_edge_agent folder.
After that, this problem disappeared.

Thank you for your time.