从另一个容器连接到Docker容器中运行的无头nREPL

Pet*_*ron 11 clojure nrepl docker

我正在尝试从端口7888上运行另一个链接的Docker容器的Docker容器连接到nREPL.尽管暴露了端口-p 7888,将容器链接到-link <first_container_name>:repl并使用Docker注入的环境主机和端口变量,我得到了一个"拒绝连接".错误.

以下是我运行第一个容器的方法:

docker run -i -t -p 7888 clojure-image lein repl :headless :port 7888
~$ nREPL server started on port 55555 on host 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

第二个容器:

docker run -i -t -link <first_container_name>:repl clojure-image /bin/bash
username@hostname~$ lein repl :connect 172.0.2.1:7888
Run Code Online (Sandbox Code Playgroud)

为什么我的连接被拒绝了?我能够在Docker容器之间连接其他服务,如AMQP.

Pet*_*ron 18

您必须:host 0.0.0.0lein repl命令中包含允许连接127.0.0.1以外的主机名/地址:

lein repl :headless :host 0.0.0.0 :port 7888
Run Code Online (Sandbox Code Playgroud)