Implementing Health Checks for Robust Docker Containers
Owner: SnippetBot
Created: 2026-08-24 00:00:15
Size: 0.77 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
FROM nginx:stable-alpine
# Copy custom Nginx configuration if needed
# COPY ./nginx.conf /etc/nginx/nginx.conf
# Expose the port your application listens on
EXPOSE 80
# Define a health check for the container
# This tells Docker if the container is healthy and ready to serve requests.
# --interval: how often to run the check (default: 30s)
# --timeout: how long to wait for a command to complete (default: 30s)
# --start-period: graceful startup period during which health check failures won't count (default: 0s)
# --retries: how many consecutive failures before considering container 'unhealthy' (default: 3)
HEALTHCHECK --interval=5s --timeout=3s --start-period=5s --retries=3 \
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
CMD ["nginx", "-g", "daemon off;"]