liveBook · Manning

Dependency check

As explained in Learn Docker in a Month of Lunches, Second Edition

A dependency check is a test that determines whether an application dependency is available and functioning sufficiently for the application to operate.

A dependency check tests whether something an application needs is available before the application starts. For a web container that calls an API, this avoids starting the web app when the API is not yet ready to answer requests. section 8.4

Listing 8.4 Utility for a dependency check at container startup
FROM diamol/dotnet-aspnet:2e

ENV RngApi:Url=http:/./numbers-api:8080/rng

CMD dotnet Utilities.HttpCheck.dll -c RngApi:Url -t 900 && \
    dotnet Numbers.Web.dll

WORKDIR /app
COPY --from=http-check-builder /out/ .
COPY --from=builder /out/ .

The Dockerfile sets the API URL in application configuration, runs a packaged HTTP-check utility, and starts the web application only if the check succeeds. The utility reads the configured URL, avoiding a second copy of it in the check command. section 8.3

Let Compose recover from a startup race

Start the API and web services with `docker compose up -d`, then inspect the containers and web logs. Without `depends_on`, the web container may start before the API is ready. Its dependency check fails, so it exits; `restart: on-failure` starts it again. Once the API responds successfully, the check passes and the web app starts. section 8.4

A dependency check runs at startup; a health check tests a running container periodically. Together, they let containers start without a guaranteed order and let a platform restart or replace containers after failures. Check dependencies carefully: repeatedly failing a container cannot repair a dependency outside the platform’s control. section 8.5

Practice with a memory requirement

For a Node.js app that simulates growing memory use, wire the supplied `memory-check.js` into the Dockerfile. Exit at startup if there is not enough memory, then run an ongoing health check every five seconds to flag excessive simulated use. section 8.6

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Shows a Dockerfile command and a Compose restart workflow using an existing utility; does not develop the utility’s implementation.
Examples
Uses a web container checking an HTTP API and a Node.js exercise checking simulated memory availability.
What it assumes
Assumes familiarity with Docker images, containers, and Compose; supplies check logic for the hands-on exercise.
What you can do after
Operate/configure it in a Dockerfile with a packaged utility, then verify failure and recovery through Docker Compose logs.
How it connects
Connects dependency checks to health checks, Docker Compose restart policies, container startup order, and self-healing applications.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.