# Dockerfile with a Health Check FROM alpine:latest # Install curl for the health check command RUN apk add --no-cache curl WORKDIR /app # Example: A simple application for demonstration purposes # Replace with your actual application setup (e.g., Python, Node.js, etc.) RUN echo 'echo "HTTP/1.1 200 OK Content-Type: text/plain OK" | nc -l -p 8000 -q 1 &' > start_app.sh RUN chmod +x start_app.sh EXPOSE 8000 # Start the application as part of the CMD CMD ["sh", "./start_app.sh"] # Define a HEALTHCHECK instruction # --interval: how often to run the check (default 30s) # --timeout: how long the check can take before failing (default 30s) # --start-period: grace period for containers to start up (default 0s) # --retries: how many consecutive failures before the container is deemed unhealthy (default 3) HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \ CMD curl --fail http://localhost:8000 || exit 1