Docker Community Forums

Share and learn in the Docker community.

Create connection from a socket in Docker container to java app on localhost

Hi,

We are using Netopeer2 in Docker on Windows 10. It is running with “Call home” function enabled. Function makes server connect to a client socket. This works when we have both client and server running in docker.
However my actual problem is when I have a java program with a server socket running on my host ( 127.0.0.1). Socket listens on port 4334. See below.

$ netstat -a | grep 4334
TCP 127.0.0.1:4334 SE-00002119:0 LISTENING

Then I enable “call home” on Netopeer2 in Docker container but there is no connection to the socket listening on port 4334.

I have started docker container with:

docker run --net host -it --name sysrepo -p 830:830 --rm netopeer2-mod-image:latest

and enabled the call home function but no connection.

Any ideas?

//mike

localhost:4334 on the host, is local to your host… and can not be seen from the container.
Try binding you service on the host to it’s ip (or 0.0.0.0) and configure the call home target to the host ip.

Thanks for reply. I could still not get it to work. Is there a way to see what sockets are opened from container?
//mike

Don’t care about my last comment. My mistake. I got it working now :slight_smile:

I’m curious about how you solved it.

I know that for Linux containers running on Docker Desktop on Windows or Mac, the local host can be accessed via host.docker.internal instead of localhost.

Is there another solution?