카우치베이스 서버

Using the Docker Healthcheck Command

One of the new features in Docker 1.12 is how health check for a container can be baked into the image definition. And this can be overridden at the command line. Just like the CMD instruction, there can be multiple HEALTHCHECK instructions in Dockerfile but only the last one is effective.

This is a great addition because a container reporting status as Up 1 hour may return errors. The container may be up but there is no way for the application inside the container to provide a status. This instruction fixes that.

그 Dockerfile that builds arungupta/couchbase image is:

It uses configure-node.sh script to configure the server using Couchbase REST API. The new instruction to notice here is HEALTHCHECK. This instruction can be specified as:

그 can be:

  • --interval=DURATION (default 30s)
  • --timeout=DURATION (default 30s)
  • --retries=N (default 3)

그 is the command that runs inside the container to check it’s health. If health check is enabled, then the container can have three states:

  • starting – Initial status when the container is still starting
  • healthy – If the command succeeds then the container is healthy
  • unhealthy – If a single run of the  takes longer than the specified timeout then it is considered unhealthy. If a health check fails, retries will be run several times and the Docker container status will be declared unhealthy if it still fails.

The Docker commands exit status indicates the HEALTHCHECK status of the container. The following values are allowed:

  • 0 – container is healthy
  • 1 – container is not healthy

In our instruction, /pools REST API is invoked using curl. If the command fails then an exit status of 1 is returned, and this marks the container unhealthy for that attempt. This Docker HEALTHCHECK command is invoked every 5 seconds. The container is marked unhealthy if the command does not return successfully within 3 seconds. Run the container as:

Check Docker container status:

Notice how health: starting status is reported in the STATUS column. Checking after a few seconds shows the status:

And now it’s reported healthy. More details about this HEALTHCHECK instruction can be found on docs.docker.com. Now, if you are running an image that does not have HEALTHCHECK instruction then the docker run command can be used to specify similar values. An equivalent runtime command would be:

Last 5 health checks for a container can be obtained using the docker inspect command:

The output is shown as:

이 기사 공유하기

작가

아룬 구프트는 Couchbase의 개발자 옹호 부문 부사장입니다. 그는 Sun, Oracle, Red Hat에서 10년 이상 개발자 커뮤니티를 구축하고 이끌었습니다. 그는 복수 기능군을 갖춘 팀을 이끌고 전략, 계획, 실행, 콘텐츠, 마케팅 캠페인 및 프로그램 개발과 실행에 대한 깊은 전문 지식을 보유하고 있습니다. 그 이전에는 Sun의 엔지니어링 팀을 이끌었으며, Java EE 팀의 창립 멤버입니다. 구푸타는 기술 분야에 대한 2,000개 이상의 블로그 게시물을 작성했습니다. 그는 수많은 주제에 대해 40개 이상의 국가에서 폭넓은 강연 경험을 보유하고 있으며, 3년 연속 JavaOne Rock Star상을 수상했습니다. 또한 그는 미국에서 Devoxx4Kids 지부를 설립했으며, 어린이들에게 기술 교육을 지속적으로 추진하고 있습니다. 기술 분야에 대한 다수의 책의 저자이자 열정적인 러너인 그는 전 세계를 누비며 Java Champion로 활동하고 있으며, JUG 리더이자 JUG Dream Team 멤버인 NetBeans Dream Team의 일원입니다. 그는 @arungupta라는 계정을 통해 쉽게 연락하실 수 있습니다.

댓글 남기기

데이터베이스의 확장성을 과거의 일로 남겨두세요

각 스택 추가마다 추가 비용이 발생하고 관리해야 할 항목도 더 많아집니다. 2분 안에 절약할 수 있는 금액을 추산해 보세요.