Skip to content

Instantly share code, notes, and snippets.

@phuysmans
Created January 8, 2018 09:29
Show Gist options
  • Star 68 You must be signed in to star a gist
  • Fork 14 You must be signed in to fork a gist
  • Save phuysmans/4f67a7fa1b0c6809a86f014694ac6c3a to your computer and use it in GitHub Desktop.
Save phuysmans/4f67a7fa1b0c6809a86f014694ac6c3a to your computer and use it in GitHub Desktop.
docker compose health check example
version: '2.1'
services:
php:
tty: true
build:
context: .
dockerfile: tests/Docker/Dockerfile-PHP
args:
version: cli
volumes:
- ./src:/var/www/src
- ./tests:/var/www/tests
- ./build:/var/www/build
- ./phpunit.xml.dist:/var/www/phpunit.xml.dist
depends_on:
couchbase:
condition: service_healthy
memcached:
condition: service_started
mysql:
condition: service_healthy
postgresql:
condition: service_healthy
redis:
condition: service_healthy
couchbase:
build:
context: .
dockerfile: tests/Docker/Dockerfile-Couchbase
healthcheck:
test: ["CMD", "curl", "-f", "http://Administrator:password@localhost:8091/pools/default/buckets/default"]
interval: 1s
timeout: 3s
retries: 60
memcached:
image: memcached
# not sure how to properly healthcheck
mysql:
image: mysql
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
- MYSQL_ROOT_PASSWORD=
- MYSQL_DATABASE=cache
healthcheck:
test: ["CMD", "mysql" ,"-h", "mysql", "-P", "3306", "-u", "root", "-e", "SELECT 1", "cache"]
interval: 1s
timeout: 3s
retries: 30
postgresql:
image: postgres
environment:
- POSTGRES_PASSWORD=
- POSTGRES_DB=cache
healthcheck:
test: ["CMD", "pg_isready"]
interval: 1s
timeout: 3s
retries: 30
redis:
image: redis
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 1s
timeout: 3s
retries: 30
@HabeebCycle
Copy link

Great config file.
Thanks buddy

@danmutblix
Copy link

@phuysmans, thanks man 🐱‍👤

@nathanfranke
Copy link

test: redis-cli ping if you want to be a bit neater :)

@wajdijurry
Copy link

condition parameter is no longer supported by docker v3.0 and above

@helmiItsavirus
Copy link

@wajdijurry
Thanks for the information

@ovcharenkoo
Copy link

Thanks a lot, wish found it yesterday

@srstsavage
Copy link

@wajdijurry Not true, condition is supported by the compose specification:

https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1

@danmutblix
Copy link

@wajdijurry Not true, condition is supported by the compose specification:

https://github.com/compose-spec/compose-spec/blob/master/spec.md#long-syntax-1

Yo, do you see the version 👆 (2.1)
Think before you write plz

@nessor
Copy link

nessor commented Jun 15, 2021

Think before you write plz

Please don't be mean. It doesn't do anyone any good and only spreads a bad mood.
We're all in the same boat.

@srstsavage
Copy link

@danmutblix Actually this does work with the docker-compose 2.1 format:

$ docker-compose config
services:
  nginx:
    depends_on:
      postgres:
        condition: service_healthy
    image: nginx:1.20
  postgres:
    environment:
      POSTGRES_PASSWORD: test
    healthcheck:
      test: pg_isready
    image: postgres:13
version: '2.1'

$ docker-compose up -d
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Creating network "ok_default" with the default driver
Creating ok_postgres_1 ... done
Creating ok_nginx_1    ... done
$ 

condition was removed for the 3.x compose format but reintroduced with the compose specification. So, it worked in 2.1+ and it works now.

🤷‍♂️ Think before you write plz 🤷‍♂️

@danmutblix
Copy link

@danmutblix Actually this does work with the docker-compose 2.1 format:

$ docker-compose config
services:
  nginx:
    depends_on:
      postgres:
        condition: service_healthy
    image: nginx:1.20
  postgres:
    environment:
      POSTGRES_PASSWORD: test
    healthcheck:
      test: pg_isready
    image: postgres:13
version: '2.1'

$ docker-compose up -d
Building with native build. Learn about native build in Compose here: https://docs.docker.com/go/compose-native-build/
Creating network "ok_default" with the default driver
Creating ok_postgres_1 ... done
Creating ok_nginx_1    ... done
$ 

condition was removed for the 3.x compose format but reintroduced with the compose specification. So, it worked in 2.1+ and it works now.

🤷‍♂️ Think before you write plz 🤷‍♂️

Okay, my bad. I'm sorry.
Have a gr8 day and thx for clearing this up 👍

@danmutblix
Copy link

Think before you write plz

Please don't be mean. It doesn't do anyone any good and only spreads a bad mood.
We're all in the same boat.

Yes, I'm sorry 😔

@nathanfranke
Copy link

We're literally working with docker health checks, it's too easy to get frustrated with this stuff

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