# Controlling startup order of services -- docker compose parsing error

**URL:** <https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983>\
**Category:** Product support\
**Created:** [April 20, 2018, 10:48am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983 "2018-04-20T10:48:28Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![ionita](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@ionita](https://forums.balena.io/u/ionita)\
**Post date:** [April 20, 2018, 10:48am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/1 "2018-04-20T10:48:28Z")

</div>

Hi, I am trying to introduce starting conditions for containers, so that they wait for each other before starting. I am currently doing this with healthchecks.

Here is how my docker-compose.yml looks like:

> version: ‘2.1’
> 
> init:  
> build: ./init  
> healthcheck:  
> test: ./all\_ready.sh  
> interval: 20s  
> timeout: 10s  
> retries: 10
> 
> network:  
> build: ./network  
> depends\_on:  
> init:  
> condition: service\_healthy

When pushing this to resin remote, I get

> [Error] Could not parse compose file  
> [Error] Service dependencies must be an array  
> [Error] Not deploying release.

I tried adding “-” in front of the depending service, but this lead to another parsing error.

I tried this docker compose syntax for a docker container outside resin and it worked. Any idea how to fix this in resin?

---

<div class="post-metadata">

**Author:** ![lekkas](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/lekkas/32/78_2.png) [@lekkas](https://forums.balena.io/u/lekkas)\
**Post date:** [April 20, 2018, 3:02pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/4 "2018-04-20T15:02:44Z")

</div>

Hi @ionita ,

This does look like a syntax error, but I cannot tell with much confidence with the existing formatting.

Could you please upload the docker-compose.yml instead? That way the indentation will be kept and it’ll be easier for us to spot any errors there.

Thanks!

---

<div class="post-metadata">

**Author:** ![ionita](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@ionita](https://forums.balena.io/u/ionita)\
**Post date:** [April 20, 2018, 3:32pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/5 "2018-04-20T15:32:14Z")

</div>

Hi @lekkas,

thanks for the reply! Here is the file (renamed from yml to log, as it was otherwise not possible to upload it):

[docker-compose.log](https://forums.balena.io/uploads/short-url/dqBZNUVbTkacwiAz466inRE8RPM.log) (387 Bytes)

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [April 20, 2018, 4:36pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/6 "2018-04-20T16:36:00Z")

</div>

I think that behaviour is not yet supported by us. Looking at the cocker compose file reference:

> **[Compose file version 2 reference](https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on)**
>
> Reference and guidelines These topics describe version 2 of the Compose file format. Compose and Docker compatibility matrix There are several versions of the Compose file format – 1, 2,...

`depends_on` was added in version `2` of docker compose, that we support, and the condition added in `2.1`.

As our [docs mention](https://docs.resin.io/reference/supervisor/docker-compose/#docker-compose-yml-fields), only the version 2’s array format is supported, and that is without the `condition`, just as

```auto
...
  network:
    build: ./network
    depends_on:
      - init
...

```

We’ll open an internal issue for this. In the meantime, the Docker documentation has some hints how to use a bit of extra tooling to replicate that behaviour, if I read it well.

> **[Control startup and shutdown order in Compose](https://docs.docker.com/compose/startup-order/)**
>
> You can control the order of service startup and shutdown with the depends\_on option. Compose always starts and stops containers in dependency order, where dependencies are determined by depends\_on, links,...

Let us know if you tried it out, and whether it works…

---

<div class="post-metadata">

**Author:** ![ionita](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@ionita](https://forums.balena.io/u/ionita)\
**Post date:** [May 13, 2018, 11:22am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/8 "2018-05-13T11:22:48Z")

</div>

Hi @imrehg, thanks for you answer! I did indeed used some wrapper scripts to delay the start of containers, after the example of wait-for-\*

`command: wait-for-container1.sh start-container2`

With the healthcheck option I would still have a script executing, maybe it is also a bit more transparent. So looking forward to seeing it supported in the future.

---

<div class="post-metadata">

**Author:** ![jason10](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jason10/32/1464_2.png) [@jason10](https://forums.balena.io/u/jason10)\
**Post date:** [March 8, 2019, 6:03am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/10 "2019-03-08T06:03:12Z")

</div>

Does the command put in the compose file replace the command in the dockerfile.template?  
Or are the separate?

- "If dockercompose.container1.command then
  - start container1
    - container1.cmd

---

<div class="post-metadata">

**Author:** ![jason10](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jason10/32/1464_2.png) [@jason10](https://forums.balena.io/u/jason10)\
**Post date:** [March 8, 2019, 6:24am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/13 "2019-03-08T06:24:59Z")

</div>

Also, got this error:

```
[Error] Could not parse compose file
[Error] data/services/camera should NOT have additional properties
[Error] Not deploying release.

```

With this compose fragment:

```
  camera:
    build: ./Camera
    healthcheck:
      test: ["CMD", "curl", "-f", "http://barnserv:80"]
      interval: 30s
      timeout: 10s
      retries: 5
```

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [March 8, 2019, 9:00am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/15 "2019-03-08T09:00:13Z")

</div>

The following docker-compose.yml is accepted fine for me:

```auto
version: '2.1'
services:
  camera:
    build: ./Camera
    healthcheck:
      test: ["CMD", "curl", "-f", "http://barnserv:80"]
      interval: 30s
      timeout: 10s
      retries: 5

```

Are you sure you specify `version: '2.1'`?

---

<div class="post-metadata">

**Author:** ![jason10](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jason10/32/1464_2.png) [@jason10](https://forums.balena.io/u/jason10)\
**Post date:** [March 8, 2019, 12:26pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/17 "2019-03-08T12:26:09Z")

</div>

No, I had version 2.  
Is there any reason to specify version 2 vs version 2.1 other than the healthcheck field?

Version 2 examples:

- [https://github.com/balena-io-playground/multicontainer-metrics/blob/master/docker-compose.yml](https://github.com/balena-io-playground/multicontainer-metrics/blob/master/docker-compose.yml)
- [https://github.com/balena-io-playground/balena-rtc-multicontainer/blob/master/docker-compose.yml](https://github.com/balena-io-playground/balena-rtc-multicontainer/blob/master/docker-compose.yml)
- [https://github.com/balena-io-projects/multicontainer-demo-rpi3/blob/master/docker-compose.yml](https://github.com/balena-io-projects/multicontainer-demo-rpi3/blob/master/docker-compose.yml)

---

<div class="post-metadata">

**Author:** ![hedss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/hedss/32/210_2.png) [@hedss](https://forums.balena.io/u/hedss)\
**Post date:** [March 8, 2019, 1:28pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/18 "2019-03-08T13:28:40Z")

</div>

Hi,

That’s correct, if you do want the healthchecks you will have to specify `2.1` instead of `2.0`.

Best regards, Heds

---

<div class="post-metadata">

**Author:** ![alethenorio](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@alethenorio](https://forums.balena.io/u/alethenorio)\
**Post date:** [May 4, 2020, 8:09am UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/21 "2020-05-04T08:09:24Z")

</div>

The healthcheck option is nice but it does not do anything if another service cannot depend on it. I have had the case where a service only exists to expose kernel modules and in this case a simple file written to the filesystem of that service is enough to say “I am done” and therefore having a script running on services that depend on that does not work since they cannot look inside the dependant service filesystem.

I honestly think that we are missing a proper way of a service depending on the healthcheck of another services

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [May 4, 2020, 1:31pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/23 "2020-05-04T13:31:16Z")

</div>

Would not what you are suggesting be resolved with named volumes, or I am misunderstanding your comment? E.g.

```auto
services:
    one:
        volumes:
            - lock-volume: /some/location/in/container
    two:
        volumes:
            - lock-volume: /some/location/in/container
volumes:
     lock-volume: 

```

---

<div class="post-metadata">

**Author:** ![alethenorio](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@alethenorio](https://forums.balena.io/u/alethenorio)\
**Post date:** [May 4, 2020, 2:03pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/25 "2020-05-04T14:03:55Z")

</div>

I meant services which are doing something like `insmod` to make kernel modules available to other services however what you have described is another setup.

In your example service `one` could be a service which exposes some files required by service `two`. This means service `two` depends on service `one`being done.

So in the setup you described service `one` and `two` will come up at the same time which might not work. Using `depends_on` can help however balena only waits for the container to start while service `one` can take some time to be finished with making those files available.

This is what the `condition` part of `depends_on` is solving which we are missing today in Balena

---

<div class="post-metadata">

**Author:** ![majorz](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/majorz/32/639_2.png) [@majorz](https://forums.balena.io/u/majorz)\
**Post date:** [May 4, 2020, 2:52pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/26 "2020-05-04T14:52:09Z")

</div>

The `condition` form of `depends_on` is removed in version 3 of docker-compose. Will an alternative method work for you like the ones explained in [https://docs.docker.com/compose/startup-order/](https://docs.docker.com/compose/startup-order/)?

---

<div class="post-metadata">

**Author:** ![alethenorio](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@alethenorio](https://forums.balena.io/u/alethenorio)\
**Post date:** [May 7, 2020, 3:44pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/28 "2020-05-07T15:44:58Z")

</div>

Yeah I noticed it was removed in version 3 sadly. Has no replacement been specified? I saw just yesterday that docker has recently published official specs for the docker compose so maybe something can be used from there.

An alternative method would of course suit us however the alternative method you linked requires that the container which depends on some service to have a way to ask the dependant service whether it is done doing what needs to be done. In the cases where the dependant service does not expose an external API for that it does not work.

This is why the healthcheck is a good option as it exposes an external API to docker compose that other servicers can query on so the service does not have to do this.

While it would be possible to expose something for other service to query for a dependency, there’s some elegance in providing that on a docker compose level so underlying services don’t have to implement that themselves

---

<div class="post-metadata">

**Author:** ![jviotti](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jviotti/32/220_2.png) [@jviotti](https://forums.balena.io/u/jviotti)\
**Post date:** [May 7, 2020, 4:36pm UTC](https://forums.balena.io/t/controlling-startup-order-of-services-docker-compose-parsing-error/2983/29 "2020-05-07T16:36:30Z")

</div>

Hey there! I totally get your concerns. We’ve talked about leveraging the `healthcheck` ([https://docs.docker.com/compose/compose-file/#healthcheck](https://docs.docker.com/compose/compose-file/#healthcheck)) options in combination with the `depends_on` option accomplish this, but its not something that’s in place right now (or will be for sure)
