Commands used in this demo:
docker run -d -p 81:80 \
--name=healthy \
--health-cmd='stat /usr/share/nginx/html/index.html || exit 1' \
--health-interval=30s \
--health-start-period=3m \
nginx:1.14
Dockerfile
FROM nginx:1.14
HEALTHCHECK --interval=5m --timeout=3s \
CMD curl -f http://localhost/ || exit 1
docker-compose.yml
version: '3'
services:
web:
image: nginx:1.14
ports:
'81:80'
healthcheck:
test: stat /usr/share/nginx/html/index.html || exit 1
interval: 1m30s
timeout: 10s
retries: 3