# unable to loop script, container doesn't exit.

**URL:** <https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655>\
**Category:** Project help\
**Tags:** docker\
**Created:** [February 12, 2023, 8:13pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655 "2023-02-12T20:13:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![puccaso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/puccaso/32/8453_2.png) [@puccaso](https://forums.balena.io/u/puccaso)\
**Post date:** [February 12, 2023, 8:13pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655/1 "2023-02-12T20:13:27Z")

</div>

hello everyone 👋

I have a script setup or raspberrypi cam. the container itself just runs the script, which is a while-true loop taking pictures with raspiberrypi and then sleeping for 10 minutes, and then back to the loop.

this bit works fine.  
what is not working is that even though the images should continue without end - it only takes about 40 images or so, for like 4/5 hours, and then stops.

worst case scenario - i’d like to container to restart (to restart for loop on reboot), but that doesn’t even happen -it just sits there.

any ideas as to what might be causing this, or what to look out for in journal/supervisor logs

regards,

puc

---

<div class="post-metadata">

**Author:** ![puccaso](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/puccaso/32/8453_2.png) [@puccaso](https://forums.balena.io/u/puccaso)\
**Post date:** [February 15, 2023, 10:26pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655/2 "2023-02-15T22:26:29Z")

</div>

update:  
so my dockerfile has entrypoint where I run a start.sh  
while troubleshooting, I saw:

> **[GitHub - balena-io-experimental/balena-rpi-python-picamera: balena + python +...](https://github.com/balena-io-experimental/balena-rpi-python-picamera)**
>
> balena + python + raspberry pi camera module. Contribute to balena-io-experimental/balena-rpi-python-picamera development by creating an account on GitHub.

and they are using CMD instead of Entrypoint.

Whats the difference here? just to understand - if this balena-experiment repo Dockerfile used an ENTRYPOINT instead of CMD, what would the outcome be?

puc

---

<div class="post-metadata">

**Author:** ![ramirogm](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@ramirogm](https://forums.balena.io/u/ramirogm)\
**Post date:** [February 17, 2023, 1:22pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655/3 "2023-02-17T13:22:20Z")

</div>

Hi, and welcome to the forums!

Regarding your first message, there could be several reasons why the app stops working. You can check the device logs by several means. If you like to use the terminal, you can go to your device homepage, open a HostOS terminal and run `journalctl`; this will show logs from all containers, os, supervisor and kernel. You can also see the container logs on the “Logs” section, but from your message it looks like the app is not logging anything.

Are you deploying the app using [docker-compose](https://docs.balena.io/reference/supervisor/docker-compose/)? You could use the `healthcheck` property to have the engine auto-restart a non-responsive container

Ramiro

---

<div class="post-metadata">

**Author:** ![ramirogm](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@ramirogm](https://forums.balena.io/u/ramirogm)\
**Post date:** [February 17, 2023, 1:33pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655/4 "2023-02-17T13:33:42Z")

</div>

About the difference between `CMD` and `ENTRYPOINT`, if you’re not overriding them on your `docker-compose` or `docker run` command, there is no practical difference.

An explanation that I like is that the `CMD` is run from `ENTRYPOINT`, and the default `ENTRYPOINT` is `/bin/sh -c`

So if you want your image to run a command on a shell, you can just specify `CMD`. If you want to replace the shell and execute a process directly, you can use your own `ENTRYPOINT`

This is another good explanation:

- CMD sets default command and/or parameters, which can be overwritten from command line when docker container runs.
- ENTRYPOINT command and parameters will not be overwritten from command line. Instead, all command line arguments will be added after ENTRYPOINT parameters.

hth  
Ramiro

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [February 17, 2023, 4:59pm UTC](https://forums.balena.io/t/unable-to-loop-script-container-doesnt-exit/366655/5 "2023-02-17T16:59:23Z")

</div>

@puccaso just to complement my colleague’s message, did you try the `cron` block?

> **[balenaHub: an easier way to find and publish fleets, apps, and blocks for...](https://hub.balena.io/organizations/gh_rcooke_warwick/blocks/cron)**
>
> balenaHub is a catalog of IoT and edge projects created by a community of product builders, like you. Find a project to try, add your devices, and begin, or publish your project today.

Let us know if this helps 🙂
