Docker Community Forums

Share and learn in the Docker community.

Linking two containers?

docker

(Siddharth67) #1

Hi guys, I have an cassandra container and an nodejs + cassandra microservice image in Docker.

I want to link these two containers, so after running poklet/cassandra image with conatiner name cassandra-3, for linking I used command,
docker run -it -p 9000:8080 --link cassandra-3:cass siddharth67/nodejs_cassandra ./bin/bash

But after running my service, it is not able to connect to the cassandra DB.
Error,
Cassandra driver was not able to connect to 127.0.0.1: Error: All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED. See innErrors.

The port 9042 is exposed.

Any help is appreciated.
Thanks


(Timgriffiths) #2

Adding a link like this will add a host file entry to your nodejs app container called “cass” so it looks like you just need to update your nodejs config to connect to Cassandra using the host name “cass” on normal port 9042


(Siddharth67) #3

Thanks timgriffiths, in my node application the host was 127.0.0.1 where as the pokle/cassandra env variable host was 172.17.0.2.
After changing the host value. Linking was perfect.