Add a HEALTHCHECK to a Dockerfile for a web app without installing curl.
IntermediateHands-onWrite-a-Dockerfile tasks
Answer
FROM python:3.12-slim
# ...
HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=2).status == 200 else 1)"
Key trick → Use the runtime the image already has (Python, Node, or the app binary's own healthcheck subcommand) instead of adding curl. Note that Kubernetes ignores HEALTHCHECK; it uses probes.
More on Write-a-Dockerfile tasks
Write a production Dockerfile for a Node.js API using a multi-stage build.IntermediateWrite a Dockerfile for a Python Flask app that runs with gunicorn as a non-root user.BeginnerWrite a Dockerfile for a Go service that produces a tiny image (under 20 MB).IntermediateWrite a multi-stage Dockerfile for a Java Spring Boot app built with Maven.IntermediateWrite a Dockerfile for a static React site served by Nginx.BeginnerThis Dockerfile rebuilds dependencies on every code change. Fix it.Beginner