Running isn't the same as working
A process can be alive but useless — stuck, or unable to reach its database. A health check is a command Docker runs regularly inside the container; orchestrators use the result to route traffic, restart containers and wait before starting dependants.
HEALTHCHECK
FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --omit=dev COPY . . ENV NODE_ENV=production EXPOSE 3000 HEALTHCHECK --interval=30s CMD wget -qO- http://localhost:3000/health || exit 1 CMD ["node", "server.js"]
- docker ps shows (healthy) or (unhealthy).
- docker logs NAME (--tail N, -f to follow) — apps should log to stdout/stderr.
- --restart unless-stopped restarts crashed containers.