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.
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- 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.
@shin- Can you explain what would need to change and perhaps somebody could have a go at helping out?
This fix doesn't appear to work if a dependee exits before its healthcheck can report a healthy
or unhealthy
status.
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.
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.
What about displaying a warning message when running docker-compose run ...
to explain healthcheck
is not taken in account? (if this can save some debugging hours to devs ^^)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed because it had not recent activity during the stale period.
Most helpful comment
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: