Healthcheck
With curl
Section titled “With curl”Health check in docker-compose.yml is usually done as:
healthcheck: test: ['CMD', 'curl', '--fail', 'http://localhost:${{ PORT }}${{ ENDPOINT }}'] interval: 10s timeout: 5s retries: 5Without curl (minimal images)
Section titled “Without curl (minimal images)”When curl or wget are not available the same can be achieved using the
following healthcheck.sh script:
#!/bin/bash
exec 5<> /dev/tcp/localhost/${{ PORT }}cat <&5 &printf "GET ${{ ENDPOINT }} HTTP/1.0\r\n\r\n" >&5Wire it in via a volume mount:
volumes: - ./healthcheck.sh:/healthcheck.shhealthcheck: test: ['CMD', '/healthcheck.sh'] interval: 10s timeout: 5s retries: 5