Howto connect to NREPL in docker container

545 Views Asked by At

Has anyone been able to bind to a [java.net InetSocketAddress ServerSocket] from inside docker? I have a simple NRepl process running in a docker container. But I can't connect to that NRepl process.

My docker-compose.yml looks something like this.

version: '3'
services:
  foo:
    ports:
      - ${NREPL_PORT:-7001}:7001

In the dockerized app, something like below is happening to bind to a host/port.

InetSocketAddress ia = new InetSocketAddress("0.0.0.0" 7001);

ServerSocket s = new ServerSocket();
s.setReuseAddress(true);
s.bind(ia);

But I consistently get an error when trying to connect from outside of docker.

λ lein repl :connect localhost:7001
Connecting to nREPL at localhost:7001
SocketException The transport's socket appears to have lost its connection to the nREPL server
        nrepl.transport/bencode/fn--9182/fn--9183 (transport.clj:108)
        nrepl.transport/bencode/fn--9182 (transport.clj:108)
        nrepl.transport/fn-transport/fn--9150 (transport.clj:55)
        clojure.core/binding-conveyor-fn/fn--5739 (core.clj:2030)
        java.util.concurrent.FutureTask.run (FutureTask.java:266)
        java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
        java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
        java.lang.Thread.run (Thread.java:745)

I've tried to listen on these addresses (listening to localhost wouldn't be available from the docker host), but I get the same error every time.

  "0.0.0.0"
  "::"

And on running, I check and have the expected ports open.

λ docker ps
CONTAINER ID    IMAGE      COMMAND       CREATED         STATUS         PORTS                     NAMES
4d39d81fba69    api_api    "lein run"    5 minutes ago   Up 5 minutes   0.0.0.0:7001->7001/tcp    api_api_1

These are similar questions (a, b) that didn't quite help in my case.

0

There are 0 best solutions below