All Projects → Soluto → golang-docker-healthcheck-example

Soluto / golang-docker-healthcheck-example

Licence: MIT license
Simple HEALTHCHECK solution for Go Docker container

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to golang-docker-healthcheck-example

nodejs-health-checker
This is a Node package that allows you to track the health of your application providing readiness and liveness functionalities.
Stars: ✭ 34 (+13.33%)
Mutual labels:  healthcheck
aarogya seva
A beautiful 😍 covid-19 app with self - assessment and more.
Stars: ✭ 118 (+293.33%)
Mutual labels:  healthcheck
sickbay
Get the HTTP status of a bunch of URLs in a single JSON response. Ideal for monitoring a lot of services at once.
Stars: ✭ 19 (-36.67%)
Mutual labels:  healthcheck
python-holdup
A tool to wait for services and execute command. Useful in Docker containers.
Stars: ✭ 29 (-3.33%)
Mutual labels:  healthcheck
gorift
A toolkit for reverse proxy and load balancer
Stars: ✭ 20 (-33.33%)
Mutual labels:  healthcheck
nginx-healthcheck-plugin
Active health checks and monitoring of Nginx upstreams
Stars: ✭ 15 (-50%)
Mutual labels:  healthcheck
golang-health-checker
A simple package to allow you to track your application healthy
Stars: ✭ 12 (-60%)
Mutual labels:  healthcheck
chip
📦 🐳 🚀 - Smart "dummy" mock for cloud native tests
Stars: ✭ 19 (-36.67%)
Mutual labels:  healthcheck
ngx stream upstream check module
nginx health checker (tcp/udp/http) for stream upstream servers.
Stars: ✭ 18 (-40%)
Mutual labels:  healthcheck
microservice-graph-explorer
Navigate and explore all of the microservices in your application in real time using the real application connections.
Stars: ✭ 71 (+136.67%)
Mutual labels:  healthcheck
health-go
A golang implementation of the upcoming IETF RFC Health Check Response Format for HTTP APIs
Stars: ✭ 31 (+3.33%)
Mutual labels:  healthcheck
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+100%)
Mutual labels:  healthcheck
laracom
laracom driven by go micro services
Stars: ✭ 37 (+23.33%)
Mutual labels:  healthcheck
maikai
RFC-compliant, Kubernetes-ready, intelligent health check middleware for HTTP APIs and microservices written in Node
Stars: ✭ 23 (-23.33%)
Mutual labels:  healthcheck
ping
A WAR Ping For JavaEE 7 Application Servers
Stars: ✭ 51 (+70%)
Mutual labels:  healthcheck
watcher
watcher(守望者)提供java应用暴露监控/健康检查的能力。
Stars: ✭ 65 (+116.67%)
Mutual labels:  healthcheck
healthz
Easily add health checks to your go services
Stars: ✭ 21 (-30%)
Mutual labels:  healthcheck
fastapi-health
Implement the Health Check API pattern on your FastAPI application! 🚀
Stars: ✭ 110 (+266.67%)
Mutual labels:  healthcheck
rfc-healthcheck
Health Check Response RFC Draft for HTTP APIs
Stars: ✭ 110 (+266.67%)
Mutual labels:  healthcheck
Mining-Minds
Mining Minds is a collection of services, tools and techniques working collaboratively to investigate on human’s daily routines to provide a personalized well-being and health-care support
Stars: ✭ 43 (+43.33%)
Mutual labels:  healthcheck

Golang Docker HEALTHCHECK

Simple HEALTHCHECK solution for Go Docker container

License

How it began

At Soluto we are working on an open-source project named Tweek. One of its components is a proxy server that we decided to implement in Go.

In order to dockerize our environment we wrote Dockerfile for the server. We built the container from scratch since it's popular in Go.

# Stage 1: Build executable
FROM golang:1.9.2 as buildImage
 
WORKDIR /go/src/github.com/Soluto/golang-docker-healthcheck
COPY main.go .

RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o server

# Stage 2: Create release image
FROM scratch as releaseImage

COPY --from=buildImage /go/src/github.com/Soluto/golang-docker-healthcheck/server ./server

ENV PORT=8080
EXPOSE $PORT

ENTRYPOINT [ "/server" ]

The Problem

We usually add a HEALTHCHECK instruction to our Dockerfiles and then check their status with the docker inspect command. Usually the health check performs an http request to server endpoint, and if it succeeds the server is considered in healthy condition. In Linux-based containers we do it with the curl or wget command. The problem is that in containers built from scratch there are no such commands.

Solution

We decided to add a new package that contains several lines...

_, err := http.Get(fmt.Sprintf("http://127.0.0.1:%s/health", os.Getenv("PORT")))
if err != nil {
	os.Exit(1)
}

... and then build the package as another executable, and add the HEALTHCHECK instruction to the Dockerfile

...
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o server
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o health-check "github.com/Soluto/golang-docker-healthcheck/healthcheck"

# Stage 2: Create release image
FROM scratch as releaseImage

COPY --from=buildImage /go/src/github.com/Soluto/golang-docker-healthcheck/server ./server
COPY --from=buildImage /go/src/github.com/Soluto/golang-docker-healthcheck/health-check ./healthcheck

HEALTHCHECK --interval=1s --timeout=1s --start-period=2s --retries=3 CMD [ "/healthcheck" ]
...

So we now have two executables in the docker container: the server and the health-check utility.

Conclusion

In this repository we demonstrated a health-check for a server implemented in Go, for a docker container built from scratch.

If you want to see a real-world application, please visit the Tweek project.

In general, we think this approach can be used for checks other than http requests.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].