Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to a headless nREPL running in a Docker container from another container

I'm trying to connect to an nREPL from a Docker container that is running another, linked Docker container on port 7888. Despite exposing the port with -p 7888, linking the container with -link <first_container_name>:repl and using the Docker-injected environment host and port variables, I am getting a "Connection refused." error.

Here's how I run the first container:

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

And the second container:

docker run -i -t -link <first_container_name>:repl clojure-image /bin/bash
username@hostname~$ lein repl :connect 172.0.2.1:7888

Why is my connection being refused? I am able to connect other services like AMQP between Docker containers.

like image 784
Petrus Theron Avatar asked Mar 15 '14 10:03

Petrus Theron


People also ask

Can two docker containers talk to each other?

If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network. Docker creates virtual networks which let your containers talk to each other. In a network, a container has an IP address, and optionally a hostname.


2 Answers

If you are running on a Mac, you are probably behind boot2docker, so this article helped, a lot. Here is how I connected to the container:

lein repl :connect $(boot2docker ip):7888

And thanks to: What IP do I access when using docker and boot2docker?

like image 73
Andrew Forward Avatar answered Sep 19 '22 09:09

Andrew Forward


You have to include :host 0.0.0.0 in the lein repl command to allow connections on a hostname/address other than 127.0.0.1:

lein repl :headless :host 0.0.0.0 :port 7888
like image 34
Petrus Theron Avatar answered Sep 21 '22 09:09

Petrus Theron