# Debugging Docker Containers

**URL:** <https://forums.balena.io/t/debugging-docker-containers/275194>\
**Category:** Product support\
**Created:** [March 18, 2021, 11:44am UTC](https://forums.balena.io/t/debugging-docker-containers/275194 "2021-03-18T11:44:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ko7eraven](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@ko7eraven](https://forums.balena.io/u/ko7eraven)\
**Post date:** [March 18, 2021, 11:44am UTC](https://forums.balena.io/t/debugging-docker-containers/275194/1 "2021-03-18T11:44:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nitish](https://avatars.discourse-cdn.com/v4/letter/n/34f0e0/32.png) [@nitish](https://forums.balena.io/u/nitish)\
**Post date:** [March 18, 2021, 1:30pm UTC](https://forums.balena.io/t/debugging-docker-containers/275194/4 "2021-03-18T13:30:46Z")

</div>

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:

```auto
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](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service)

---

<div class="post-metadata">

**Author:** ![ko7eraven](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@ko7eraven](https://forums.balena.io/u/ko7eraven)\
**Post date:** [March 18, 2021, 1:50pm UTC](https://forums.balena.io/t/debugging-docker-containers/275194/5 "2021-03-18T13:50:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chrisys](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrisys/32/1731_2.png) [@chrisys](https://forums.balena.io/u/chrisys)\
**Post date:** [March 18, 2021, 5:10pm UTC](https://forums.balena.io/t/debugging-docker-containers/275194/6 "2021-03-18T17:10:49Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![ko7eraven](https://avatars.discourse-cdn.com/v4/letter/k/9f8e36/32.png) [@ko7eraven](https://forums.balena.io/u/ko7eraven)\
**Post date:** [March 21, 2021, 10:15pm UTC](https://forums.balena.io/t/debugging-docker-containers/275194/8 "2021-03-21T22:15:27Z")

</div>

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