Minimal linux version for all of those gRPC services that don't provide health port.
Example with gripmock
gripmock:
image: gripmock/gripmock
ports:
- "${STUB_GRPC_PORT}:${STUB_GRPC_PORT}"
- "${STUB_ADMIN_PORT}:${STUB_ADMIN_PORT}"
volumes:
- ./stubs/service/protos:/proto:ro
- ./stubs/service/stubs:/stubs:ro
healthcheck:
# note: this checks for without netstat/nc/other tools. Also, docker is tcp6.
test: ["CMD-SHELL", "grep -q :$(printf '%04X' $$STUB_GRPC_PORT) /proc/net/tcp6"]
interval: 3s
timeout: 2s
retries: 15
command: --admin-port ${STUB_ADMIN_PORT} --grpc-port ${STUB_GRPC_PORT} --stub=/stubs /proto/service/v1/pservice.proto
The trick is here: grep -q :$(printf '%04X' $$STUB_GRPC_PORT) /proc/net/tcp6
:
- printf '%04X' $$STUB_GRPC_PORT will HEX the readable (decimal) port number
- /proc/net/tcp6 is docker default, the port will appear here once it's opened (i.e. service started successfully)