Debugging Docker Containers

If a Docker application crashes, it constantly restarts in a loop, which prevents ssh access to the container, and so it is not possible to debug why the crash happens. Any ideas how to stop the application auto-restarting ?

Thanks,

Kevin

Hi,

Can you provide a bit more details on what are you trying to run? Is this a multi-container app on balena?

For checking out individual service you can stop the service and check existing container using the following:

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"serviceName": "my-service"}'

curl --header "Content-Type:application/json" "$BALENA_SUPERVISOR_ADDRESS/v2/applications/$BALENA_APP_ID/stop-service?apikey=$BALENA_SUPERVISOR_API_KEY" -d '{"imageId": 1234}'

Ref link: Interacting with the balena Supervisor - Balena Documentation

Thanks for the prompt reply. This is a single-container python app for Balena on a PiCompute 3+. The python application is struggling to find a screen for SDL when running in a container, but works fine in the bare-metal environment. Should be easy to debug if have access to container ssh. Does the container run its own sshd on a different port to the OS sshd ?

Kevin

Hey there Kevin, if you want to be able to connect to the container for debugging after the process crashes, you can simply run a sleep command. Or, if you’re running a balena base image, you can use the balena-idle command which achieves the same thing. If the container isn’t running, there’s no way to connect to it so you’re right in that you won’t be able to connect if it keeps restarting over and over.

If you edit your Dockerfile so the CMD is ["balena-idle"] instead of the one which is crashing, the container will come up and you can connect to it via the terminal and debug. I hope this helps!

Thanks - I was able to get into the terminal and debug.