Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depends_on condition service_completed_successfully #8154

Closed
jruizvar opened this issue Feb 24, 2021 · 28 comments
Closed

Depends_on condition service_completed_successfully #8154

jruizvar opened this issue Feb 24, 2021 · 28 comments

Comments

@jruizvar
Copy link

jruizvar commented Feb 24, 2021

Description of the Issue

I wrote a compose file docker-compose.yml with two services and the option depends_on in one of the services:

version: "3.9"
services:
  second:
    depends_on:
      first:
        condition: service_completed_successfully
    image: second
  first:
    image: first

According to compose-spec:

  • condition: condition under which dependency is considered satisfied
    • service_started: is an equivalent of the short syntax described above
    • service_healthy: specifies that a dependency is expected to be "healthy"
      (as indicated by healthcheck) before starting a dependent service.
    • service_completed_successfully: specifies that a dependency is expected to run
      to successful completion before starting a dependent service.

However, the execution of docker-compose up yields:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.second.depends_on.first.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy

Environment

docker-compose version 1.28.4, build cabd5cfb
docker-py version: 4.4.3
CPython version: 3.7.10
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
Client: Docker Engine - Community
 Version:           20.10.3
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        48d30b5
 Built:             Fri Jan 29 14:33:21 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.3
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       46229ca
  Built:            Fri Jan 29 14:31:32 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.3
  GitCommit:        269548fa27e0089a8b8278fc4fc781d7f65a939b
 runc:
  Version:          1.0.0-rc92
  GitCommit:        ff819c7e9184c13b7c2607fe6c30ae19403a7aff
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
@jruizvar jruizvar changed the title Missing condition to express dependency between services Missing condition service_completed_successfully Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition service_completed_successfully Missing condition **service_completed_successfully** Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition **service_completed_successfully** depends_on is missing condition service_completed_successfully Feb 25, 2021
@jruizvar jruizvar changed the title depends_on is missing condition service_completed_successfully Missing condition for "depends_on" Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition for "depends_on" Missing condition for depends_on Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition for depends_on Missing condition using depends_on Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition using depends_on Missing condition indicating service_completed_successfully Feb 25, 2021
@jruizvar jruizvar changed the title Missing condition indicating service_completed_successfully Depends_on condition service_completed_successfully Feb 25, 2021
@portiaove
Copy link

portiaove commented Mar 4, 2021

Stumbled with the same problem on a service running Node.

My docker-compose.yml looks similar

version: "3.7"
services:
  test:
  dist:
    depends_on:
      test:
        condition: service_completed_successfully

The message prompt by the terminal:

ERROR: The Compose file './docker-compose.yml' is invalid because: services.dist.depends_on.test.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy

Any ideas?

@ashishchandr70
Copy link

Same issue with the following docker-compose.yml:

version: '3'

services:

 ...(other services defined)...

  fyx_cashier:
    build:
      context: krono-stacks/docker/cashier
      dockerfile: Dockerfile
    container_name: fyx_cashier
    depends_on: 
      fyx_mock:
        condition: service_completed_successfully
    restart: unless-stopped
    env_file: .env
    environment:
      - API=http://172.17.0.1:8080
      - NETWORK=testnet
     
networks:
  app-network:
    driver: bridge

volumes:
  dbdata:

Got this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.cryptofights.depends_on.fyx_mock.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy
services.fyx_cashier.depends_on.fyx_mock.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy
Fri Mar 12 15:17:51 CST 2021 Could not build containers for local testing. Cannot continue. Exiting

@peterroelants
Copy link

I ran into the same issue.
After doing some research it seems that the docker-compose implementation sometimes lags the docker-compose spec: compose-spec/compose-spec#144

@JakeUrban
Copy link

JakeUrban commented Apr 7, 2021

@ulyssessouza @aiordache any chance either of you could look at this?

@devopscoder331
Copy link

devopscoder331 commented Apr 12, 2021

@jruizvar @ashishchandr70 @peterroelants You have used docker-compose.yml file with string version: "3"

Version 3+ have changes:

There are several things to be aware of when using depends_on:

  • depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.
  • Version 3 no longer supports the condition form of depends_on.

Look at https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on

@peterroelants
Copy link

@devopscoder331 I've been using version: '3.8'

@devopscoder331
Copy link

@devopscoder331 I've been using version: '3.8'

Okey, but Compose file versions 3+ don't support the condition form of depends_on.

@jruizvar
Copy link
Author

That is why I labeled the issue as kind/feature, in order to have the feature back.

@devopscoder331
Copy link

devopscoder331 commented Apr 12, 2021

That is why I labeled the issue as kind/feature, in order to have the feature back.

Ooops :) now I get it

@peterroelants
Copy link

Okey, but Compose file versions 3+ don't support the condition form of depends_on.

Weird, because I can use things like:

    depends_on:
      <service-name>:
        condition: service_healthy

It's just that the service_completed_successfully does not work (what I understood this issue to be about).

@aiordache
Copy link
Contributor

Hi. Support for service_completed_successfully has been added in the latest version of docker-compose. Give it a try please: https://github.com/docker/compose/releases/tag/1.29.0

@peterroelants
Copy link

Cool, I wasn't aware of the new release a few days ago. I can confirm that with 1.29.0 using condition: service_completed_successfully works as expected.

@augustsaintfreytag
Copy link

augustsaintfreytag commented Apr 27, 2021

I was looking for exactly this and defined an app_dependencies service that sets up prerequisites and a corresponding app service that depends on it, to run only on service_completed_successfully. However, it seems the dependencies service is kicked off and the app service is started long before I eventually see…

app_dependencies exited with code 0

…in the log output. I'm using the docker compose command, though docker-compose --version confirms I'm on the version 1.29.0 mentioned here. What am I overlooking here?

@ndeloof
Copy link
Contributor

ndeloof commented Jun 17, 2021

@augustsaintfreytag docker compose issues are tracked on https://github.com/docker/compose-cli/issues

@ndeloof ndeloof closed this as completed Jun 17, 2021
@rf-0
Copy link

rf-0 commented Jun 29, 2021

Can anyone confirm service_completed_successfully works in version 2.0.0-beta.4? Dosent seem to be working for me.

@ndeloof
Copy link
Contributor

ndeloof commented Jun 30, 2021

@rf-0 at least there's an end-to-end test to check it works :P https://github.com/docker/compose-cli/blob/main/pkg/e2e/compose_test.go#L167

Please report issue on docker/compose-cli repo, and if possible attach a reproduction scenario demonstrating your issue.

mmlb added a commit to mmlb/tinkerbell-sandbox that referenced this issue Jun 2, 2022
Without this docker-compose complains about depends_on config settings:

> ERROR: The Compose file './docker-compose.yml' is invalid because:
> services.tink-server.depends_on.generate-tls-certs.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy
> services.web-assets-server.depends_on.fetch-and-convert-ubuntu-img.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy
> services.registry.depends_on.generate-tls-certs.condition contains "service_completed_successfully", which is an invalid type, it should be a service_started, or a service_healthy

This was due to docker/compose#8154.

Signed-off-by: Manuel Mendez <github@i.m.mmlb.dev>
@snoseeds
Copy link

snoseeds commented Jul 6, 2022

Okey, but Compose file versions 3+ don't support the condition form of depends_on.

Weird, because I can use things like:

    depends_on:
      <service-name>:
        condition: service_healthy

It's just that the service_completed_successfully does not work (what I understood this issue to be about).

In what version (3.?) did service_healthy work correctly as claimed here, please?

@dolfinus
Copy link

In what version (3.?) did service_healthy work correctly as claimed here, please?

3.9

bjoernricks added a commit to greenbone/docs that referenced this issue Dec 16, 2022
The `depends_on` `service_completed_successfully` config in the compose
file requires docker compose 1.29.0 actually.

See https://github.com/docker/compose/releases/tag/1.29.0 and
docker/compose#8154

Closes #230
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 27, 2022
The `depends_on` `service_completed_successfully` config in the compose
file requires docker compose 1.29.0 actually.

See https://github.com/docker/compose/releases/tag/1.29.0 and
docker/compose#8154

Closes #230
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 27, 2022
The `depends_on` `service_completed_successfully` config in the compose
file requires docker compose 1.29.0 actually.

See https://github.com/docker/compose/releases/tag/1.29.0 and
docker/compose#8154

Closes #230
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 27, 2022
The `depends_on` `service_completed_successfully` config in the compose
file requires docker compose 1.29.0 actually.

See https://github.com/docker/compose/releases/tag/1.29.0 and
docker/compose#8154

Closes #230
bjoernricks added a commit to greenbone/docs that referenced this issue Dec 27, 2022
The `depends_on` `service_completed_successfully` config in the compose
file requires docker compose 1.29.0 actually.

See https://github.com/docker/compose/releases/tag/1.29.0 and
docker/compose#8154

Closes #230
@zioalex
Copy link

zioalex commented Aug 27, 2023

In what version (3.?) did service_healthy work correctly as claimed here, please?

3.9
Version 3.9 doesn't work for me.
Can you specify which Docker version do you have?

@ndeloof
Copy link
Contributor

ndeloof commented Aug 27, 2023

In what version (3.?) did service_healthy work correctly as claimed here, please?

version attribute is deprecated in Docker Compose v2 as we adopted the Compose Specification

@ramya-1000
Copy link

As v1 is depricated what version of docker compose is supporting for depends on condition service_completed_successfully ?

@ndeloof
Copy link
Contributor

ndeloof commented Dec 4, 2023

Docker Compose v2 supports service_completed_successfully since v2.0.0 (see 15a21a4)

@jhf
Copy link

jhf commented Dec 9, 2023

When I follow the standard installation of docker, I get both a docker compose and a docker-compose command.
Notice the version difference.

$ docker-compose version
docker-compose version 1.26.0, build d4451659
docker-py version: 4.2.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

and

$ docker compose version
Docker Compose version v2.21.0

When I try with the docker-compose command, it fails, as you say @jruizvar , however, when I use the docker compose it works.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 9, 2023

@jhf check which docker-compose. This is running obsolete docker-compose v1, maybe installed manually or via pip

@jhf
Copy link

jhf commented Dec 18, 2023

@jhf check which docker-compose. This is running obsolete docker-compose v1, maybe installed manually or via pip

True @ndeloof , I have since removed that obsolete docker-compose, however the comment was for this thread, such that other people are not confused about docker compose vs docker-compose and that they check their version.
Since, as you say, the support is in recent versions of docker.
Do also note that it depends on the declared docker compose file version, as the attribute service_completed_successfully is only supported in version 2 of the syntax, and not in version 3. So one might use version: "2.4" at the beginning of the docker-compose.yml file.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 18, 2023

@jhf version: "x.y" in your compose file is obsolete, since Compose Specification was introduced 3 years ago. Forget about "version 2 of the syntax, and not in version 3" logic, all attributes are now supported.

@jhf
Copy link

jhf commented Dec 18, 2023

@jhf version: "x.y" in your compose file is obsolete, since Compose Specification was introduced 3 years ago. Forget about "version 2 of the syntax, and not in version 3" logic, all attributes are now supported.

Good news indeed 👍

@ramya-1000
Copy link

ramya-1000 commented Dec 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests