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?