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
