Search code examples
docker-composeddev

Controlling Healthcheck with a Compose file in DDEV-Local


Using DDEV Local a project will sometimes fail the healthcheck, but then eventually become available. How could someone disable the healthcheck in order to better diagnose what is happening in a container?


Solution

  • Thanks to the integration of docker-composer we can create a compose file for healthcheck and adjust its settings as needed.

    To start add a docker-compose.healthcheck.yaml file to your .ddev directory.

    Then to disable the healthcheck it should look something like this:

    version: '3.6'
    services:
      web:
        healthcheck:
          test: ['CMD','true'] //disable the healthcheck
    

    In this example we use ['CMD','true'] to force the test to pass, rather than using disable:true, because the disable key cannot be paired with other options which are set by default.

    Additionally, if you would like to adjust the timeout before a container fails you can adjust the compose file like so:

    version: '3.6'
    services:
      web:
        healthcheck:
          timeout: 30s //set how long before healthcheck fails
    

    You can also familiarize yourself more with the available options for healthcheck via the Compose File Healthcheck docs.