# Multiple containers

**URL:** <https://forums.balena.io/t/multiple-containers/301323>\
**Category:** Product support\
**Created:** [April 23, 2021, 2:37pm UTC](https://forums.balena.io/t/multiple-containers/301323 "2021-04-23T14:37:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscarthorn](https://avatars.discourse-cdn.com/v4/letter/o/87869e/32.png) [@Oscarthorn](https://forums.balena.io/u/Oscarthorn)\
**Post date:** [April 23, 2021, 2:37pm UTC](https://forums.balena.io/t/multiple-containers/301323/1 "2021-04-23T14:37:57Z")

</div>

Hi!

Is it possible to include multiple containers in a release but not actually start all of them on device start? I have some complex interactions between containers and for example container A starts container B and C (through mounting the docker socket).

---

<div class="post-metadata">

**Author:** ![gelbal](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gelbal/32/1109_2.png) [@gelbal](https://forums.balena.io/u/gelbal)\
**Post date:** [April 23, 2021, 2:50pm UTC](https://forums.balena.io/t/multiple-containers/301323/3 "2021-04-23T14:50:10Z")

</div>

Hi @Oscarthorn, for your use case does it make sense to use `depends_on` keyword?  
Docs are here: [Compose file version 2 reference | Docker Documentation](https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on)

`depends_on` controls the startup order and I’d suggest using that before looking into more complex control logic that you need to maintain as part of the application.

---

<div class="post-metadata">

**Author:** ![Oscarthorn](https://avatars.discourse-cdn.com/v4/letter/o/87869e/32.png) [@Oscarthorn](https://forums.balena.io/u/Oscarthorn)\
**Post date:** [April 23, 2021, 9:25pm UTC](https://forums.balena.io/t/multiple-containers/301323/5 "2021-04-23T21:25:04Z")

</div>

No unfortunately it does not, it not about the order of startup, we need to be able to start and stop containers dynamically and all of them do not start at device launch. So we need to be able to include containers that do not automatically start. Having everything in one container at starting things from there is also not really feasible since there can be conflicting dependencies between services.

We have it setup like this right now (containers starting other containers) and it works well for our purposes. But I’m evaluating if balena could be a good fit for our product, so that’s why I’m asking.

---

<div class="post-metadata">

**Author:** ![gelbal](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gelbal/32/1109_2.png) [@gelbal](https://forums.balena.io/u/gelbal)\
**Post date:** [April 29, 2021, 2:17pm UTC](https://forums.balena.io/t/multiple-containers/301323/9 "2021-04-29T14:17:24Z")

</div>

Hi @Oscarthorn I see. Thanks for the extra context.

As far as I know, docker-compose does not support a method to mark containers that shouldn’t be started automatically.

Checking our internal feature tracking system, I see that couple of our users and team members already raised the same feature request. I added your interest on your behalf and also pinged my teammates who maintain the relevant modules here.

In my opinion, it’s a good ask. I could imagine several scenarios that such a feature would enable. Then I cannot comment when we could work and implement this feature. For sure we will notify you here as we make progress and ask for your feedback.

Having said these, the balena supervisor already offers methods to start and stop containers from another container at demand. Here are the docs that explain how to do it: [Interacting with the balena Supervisor - Balena Documentation](https://www.balena.io/docs/reference/supervisor/supervisor-api/#post-v2applicationsappidstop-service)

Let’s say that you’d like `container-A` to orchestrate the start/stop of `container-B`. You could set the restart policy of `container-B` to `no` or `on-failure` ([Docker’s docs here](https://docs.docker.com/config/containers/start-containers-automatically/)). Then you’ll make sure that `container-B` exits (without failure) when the balena engine starts it automatically. Then using the supervisor API calls I referenced `container-A` will manage the starts and stops. You could use [device tags](https://www.balena.io/docs/reference/supervisor/supervisor-api/#device-tags) to orchestrate the whole process. The value of the device tag would imply if a specific container is supposed to be stopped or started. Using the device tags has extra benefits like bringing visibility and control of the container lifetime via the balena dashboard and API (to control / observe container lifetimes from outside of `container-A` as well).

Let us know if this would work in your case or not.

---

<div class="post-metadata">

**Author:** ![rahul-thakoor](https://avatars.discourse-cdn.com/v4/letter/r/9de053/32.png) [@rahul-thakoor](https://forums.balena.io/u/rahul-thakoor)\
**Post date:** [May 7, 2021, 5:43am UTC](https://forums.balena.io/t/multiple-containers/301323/21 "2021-05-07T05:43:11Z")

</div>

Hey @Oscarthorn

Just checking if the suggestions made by my colleague were helpful?

Let us know how it goes and if we can help with anything.

Thanks
