How to check Docker Container is Healthy or not

Basically Sometime docker container is running but the services is not running so at this point of time in every 30 sec we send a curl request if they then respond 200 then it's become Healthy

How I make it Hands-on

first i clone this app

https://github.com/SarthakTyagiji/Color_Flipper.git

There is docker file already exist do these changes in it

vim Dockerfile

Add HEALTH CHECK in it

FROM nginx:latest

WORKDIR /usr/share/nginx/html

COPY . .

EXPOSE 80

HEALTHCHECK --interval=30s --timeout=3s \
  CMD curl --fail http://localhost || exit 1

CMD ["nginx", "-g", "daemon off;"]

--interval = every 30sec it will check again and again

--timeout = if it take more then 3 sec for checking then it will show error

--retries = it will retry (like if you enter 3) 3 times before sending you final result

--start-period = it will hold (if start period is 1 m) 1 min before start checking

and build and run this

docker build -t test
docker run -p 80:80 -d test
docker ps

If You see like this then it means it's running