1

This question is similar to From inside of a Docker container, how do I connect to the localhost of the machine?, but since using --network="host" in the docker run command didn't work for me I'm asking the question again for my specific use case.

I have a Java gRPC server running locally on port 9095 which implements the gRPC health checking protocol:

> lsof -i :9095
COMMAND   PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    17538 kurtpeek   89u  IPv6 0x14676dca7273b22d      0t0  TCP *:9095 (LISTEN)

I would like to verify that this is the case by using the grpc-health-probe. Since that repository only has releases for the Linux operating system but I'm running a Mac, I'd like to do this from a Docker container which is set up to forward requests to localhost:9095 to the host machine.

Using this Dockerfile,

FROM ubuntu

RUN apt-get update && apt-get -y install lsof wget
RUN GRPC_HEALTH_PROBE_VERSION=v0.3.6 && \
    wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
    chmod +x /bin/grpc_health_probe

I built the image using docker build --tag healthprobe . and then ran it in interactive mode using the command

docker run -it --network="host" healthprobe bash

However, running /bin/grpc_health_probe -addr=:9095 did not connect successfully with the local gRPC server, and lsof doesn't show that anything is listening on that port:

root@docker-desktop:/# /bin/grpc_health_probe -addr=:9095
timeout: failed to connect service ":9095" within 1s
root@docker-desktop:/# lsof -i :9095
root@docker-desktop:/#

Should using --network="host" not ensure that lsof gives me the same result as on my local machine? How can I get this container to probe the local health server?

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526

1 Answers1

0

Why creating a new container to check health, why checking health in this scenario any way ?

Normally, grpc_health_probe is used to check health for a container in an orchestration environment like K8s. And you have to include the binary grpc_health_probe into your container and call it with localhost loopback in readiness or liveness probs like so :

          livenessProbe:
            failureThreshold: 3
            exec:
              command: ["/bin/grpc_health_probe-linux-amd64", "-addr=localhost:50051"]
            initialDelaySeconds: 60
            periodSeconds: 60
            timeoutSeconds: 30
          readinessProbe:
            failureThreshold: 3
            exec:
              command: ["/bin/grpc_health_probe-linux-amd64", "-addr=localhost:50051"]
            initialDelaySeconds: 20
            periodSeconds: 20
            timeoutSeconds: 30         

Or with docker-compose as following :

healthcheck:
            test: ["CMD", "bin/grpc_health_probe-linux-amd64", "-addr=localhost:50051"]
            interval: 30s
            timeout: 30s
            retries: 3
amine
  • 1