Docker - IP address of container on Windows

1.8k Views Asked by At

The task is follows: Write node.js server that will work with a ScyllaDB, that will be placed on Docker container. I doing this earlier, but on Ubuntu, and its work fine, now I should do it on Windows 10.

I installed Docker Toolbox for Windows and run commands from the scylladb docs.

$ docker run --name some-scylla -d scylladb/scylla
af51fa65627303db16a3de85003be8a165a64f37cf6ae29c0b4e887d64342ad2\

$ docker exec -it some-scylla cqlsh
Connected to  at 172.17.0.2:9042.
[cqlsh 5.0.1 | Cassandra 3.0.8 | CQL spec 3.3.1 | Native protocol v4]
Use HELP for help.
cqlsh> CREATE KEYSPACE nodeTask WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};

After this on my Node.js server I can set connection:

const cassandra = require("cassandra-driver")
const client = new cassandra.Client({
 contactPoints: ["127.0.0.1"],
  localDataCenter: "datacenter1",
  keyspace: "nodetask"
})

As I say its works fine on Ubuntu with this IP - 127.0.0.1, BeaverDB(GUI) connect to this IP with 9042 port as default, but on Windows its doesn't work. There is no possibility to work on Ubuntu now.

Sorry for the bad question and maybe a little information, but I'm new to this and simply don’t know what exactly I need to tell

1

There are 1 best solutions below

2
prithajnath On BEST ANSWER

127.0.0.1 is the loopback address, so your Node.js container keeps pinging itself instead of the host (your laptop). You can create your own bridge network and attach the two containers to that bridge network

docker network create scylla-net

Now run the ScyllaDB container as follows

docker run --name some-scylla -d --net=scylla-net scylladb/scylla

In your Node.js script, change the 127.0.0.1 to some-scylla (name of your ScyllaDB container). The cool thing about user-defined bridge networks is that they let your containers talk to each other via their names. So the name some-scylla would resolve to whatever IP address the some-scylla container is using at the time.

Now when you run your Node.js server, be sure to pass the --net=scylla-net flag otherwise it wouldn't be able to resolve the name some-scylla. Hope this helps!