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

Healthcheck dependency not respected during one-off command (run) #4369

Open
deeky666 opened this Issue Jan 20, 2017 · 6 comments

Comments

Projects
None yet
6 participants
@deeky666
Copy link

deeky666 commented Jan 20, 2017

First of all thanks for all you awesome work!
I checked out the healthcheck feature of v1.10 and discovered an issue when used with depends_on.
It seems the healthcheck condition defined in depends_on is ignored when using docker-compose run and not waiting for the dependency to be healthy. When using docker-compose up it works as expected.

Failing docker-compose.yml (just to reveal the issue):

version: '2.1'
services:
  db:
    image: redis
    healthcheck:
      test: "exit 1"

  test:
    image: busybox
    depends_on:
      db:
        condition: service_healthy
$ docker-compose up
Creating network "healthcheck_default" with the default driver
Creating healthcheck_db_1

ERROR: for test  Container "8f8f8d2728d3" is unhealthy.
ERROR: Encountered errors while bringing up the project.
$ docker-compose run test
Creating network "healthcheck_default" with the default driver
Creating healthcheck_db_1
/ # 
$ docker version
Client:
 Version:      1.13.0
 API version:  1.25
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 10:05:19 2017
 OS/Arch:      linux/amd64

Server:
 Version:      1.13.0
 API version:  1.25 (minimum version 1.12)
 Go version:   go1.7.3
 Git commit:   49bf474
 Built:        Tue Jan 17 10:05:19 2017
 OS/Arch:      linux/amd64
 Experimental: false
$ docker-compose version
docker-compose version 1.10.0, build 4bd6f1a
docker-py version: 2.0.1
CPython version: 2.7.9
OpenSSL version: OpenSSL 1.0.1t  3 May 2016

Is this expected behaviour? I guess not, otherwise defining such dependencies on one-off commands is misleading and doesn't make any sense.

@shin-

This comment has been minimized.

Copy link
Contributor

shin- commented Jan 24, 2017

Hi,

Unfortunately, the way the run command works makes it very complicated to honor healthcheck dependencies. It is not currently in our plans to add such a feature.

FWIW, the following workaround should achieve the same result:

version: '2.1'
services:
  db:
    image: redis
    healthcheck:
      test: "exit 1"

  proxy_dep:
    image: busybox
    depends_on:
      db:
        condition: service_healthy

  test:
    image: busybox
    depends_on:
      - proxy_dep

@shin- shin- added the kind/question label Jan 24, 2017

@deeky666

This comment has been minimized.

Copy link
Author

deeky666 commented Jan 24, 2017

@shin- thanks for clearing that up. I'm fine with the workaround. You can leave the issue open as feature proposal if you want (in case it my be possible to implement it in the future) but at least I think it should be documented somehow.

@rawkode

This comment has been minimized.

Copy link
Contributor

rawkode commented Feb 24, 2017

@shin- Can you explain what would need to change and perhaps somebody could have a go at helping out?

@ian-axelrod

This comment has been minimized.

Copy link

ian-axelrod commented Jun 7, 2017

This fix doesn't appear to work if a dependee exits before its healthcheck can report a healthy or unhealthy status.

@lwalid

This comment has been minimized.

Copy link

lwalid commented Oct 31, 2017

Hi,
I have the same error whene i use docker-compose up -d.

ERROR: for lns Container "6bbe990eb02c" is unhealthy.
ERROR: Encountered errors while bringing up the project.

@levenkov

This comment has been minimized.

Copy link

levenkov commented Aug 30, 2018

But what about using docker-compose just for running tests (e.g. rspec)? It's very convenient to simple run rspec in the container without scripts like wait-for-it.sh.

Docker used not only in restartable ways.

@normanrz normanrz referenced this issue Jan 4, 2019

Merged

Docker-compose with depends_on #3596

1 of 1 task complete

jeancochrane added a commit to open-apparel-registry/open-apparel-registry that referenced this issue Feb 4, 2019

Use Django proxy service to respect DB health check
Instead of calling pg_isready in scripts/update in order to manually
poll the database until it's healthy, use a proxy service to enforce
the database health check during calls to 'docker-compose run' as
recommended here:

docker/compose#4369 (comment)

jeancochrane added a commit to open-apparel-registry/open-apparel-registry that referenced this issue Feb 4, 2019

Use Django proxy service to respect DB health check
Instead of calling pg_isready in scripts/update in order to manually
poll the database until it's healthy, use a proxy service to enforce
the database health check during calls to 'docker-compose run' as
recommended here:

docker/compose#4369 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment