Run a CLI inside a GreenGrass docker image

0

I have a few greengrass (docker) components that listen to IPC local topics. I now want to test to see if they are actually responding to messages on the local topics so i've written a greengrass_pub application (similar to mosquitto_pub) so i can call: greengrass_pub --topic "local/topic" --payload "{ \"do_some\" : \"stuff\" } "

to check if the other components pick this up.

I have also installed this greengrass_pub application in the docker image, so i should be able to start up another docker image.

Can i startup a docker image to run under the greengrass credentials so I have access to IPC in an interactive way AND have a command prompt where I can try different calls ?

How could I start this up ? ( like a docker interactive (-it) session ? )

note: this is only for development as a tool to check.(i have the greengrass cli installed)

clogwog
asked 2 years ago380 views
2 Answers
1
Accepted Answer

Run your docker container as a docker component in Greengrass following the instructions in Use interprocess communication in Docker container components.

Then, from the shell on the host where Greengrass is running, find the container name or id via docker ps and run docker exec -it <container name/id> /bin/sh

Now you can run greengrass_pub --topic "local/topic" --payload "{ \"do_some\" : \"stuff\" } "

Is your command open source? Could you share the repo?

AWS
EXPERT
answered 2 years ago
profile picture
EXPERT
reviewed 8 days ago
0

Thank you for that suggestion Massimiliano,

I have followed the instructions to start the docker that runs the program that listens to ipc already and the container can happily listen to IoT-Core topics so i think the permissions are alright. I've also added the accessControl to allow access to local topics.

{
  "Run": "docker run --name=abcd --cap-add=SYS_PTRACE --runtime=nvidia -e DISPLAY=$DISPLAY --privileged --volume /tmp/.X11-unix:/tmp/.X11-unix --net=host -e NVIDIA_VISIBLE_DEVICES=all -v $HOME/.Xauthority:/root/.Xauthority -v /run/udev/control:/run/udev/control -v /greengrass/v2:/greengrass/v2 -e SVCUID -e AWS_GG_NUCLEUS_DOMAIN_SOCKET_FILEPATH_FOR_COMPONENT -v /dev:/dev -v /sys/firmware/devicetree/base/serial-number:/sys/firmware/devicetree/base/serial-number -v /data:/data -e NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics   xxxxxxxxxx.dkr.ecr.ap-southeast-2.amazonaws.com/smartdvr:dev3 runscript.sh"
}

runscript.sh looks like:

#!/bin/sh
ret=0
while [ $ret -eq 0 ]; do
	exec /usr/sbin/my_application_that_listens_to_ipc
	ret=$?
	sleep 30
done

when i run docker exec -it abcd /bin/sh

it shows a command prompt ( # ) but as soon as i try to use the command prompt it hangs..

i think that is because it only runs my_application_that_listens_to_ipc .. and i'm not sure that exec can start another 'session' ?

clogwog
answered 2 years ago
  • I had to change the exec to something else, and then it allowed me to docker exec -it into it. thank you

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions