Can't connect to nats streaming server in Docker cluster
See original GitHub issueIt seems I get a connection time out every time I try to connect to a cluster on the docker container. I have no problem connecting with the Nats Client. The streaming client works until I turn on clustering.
Here’s how I fire up the cluster.
docker network create --driver bridge nats-cluster
docker run --network=nats-cluster -it --name a -p 0.0.0.0:4222:4222 -p 0.0.0.0:4248:4248 -v C:/data:/data nats-streaming -cid mycluster -st FILE -dir /data/a -cluster_log_path /data/mycluster --clustered --cluster_node_id a --cluster_peers b --cluster nats://0.0.0.0:4248 -routes nats-route://b:5248 -SDV
Here’s how I try to connect
var factory = new StanConnectionFactory();
var opts = StanOptions.GetDefaultOptions();
opts.NatsURL = "nats://localhost:4222";
var connection = factory.CreateConnection("mycluster", "mytestapp", opts);
Here’s the exception
STAN.Client.StanConnectRequestTimeoutException: ‘Connection Request Timed out.’
The non streaming client works fine. No errors doing this:
var fac = new ConnectionFactory();
var opts = ConnectionFactory.GetDefaultOptions();
opts.Url = "nats://localhost:4222";
fac.CreateConnection(opts);
navigating to localhost:8222 still brings up the monitor, I just can’t make a connection using the nats streaming client.
Am I doing something wrong?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Server Cannot find NATS from inside Docker Container
The server tries to send messages through NATs. To connect to NATs, it uses the following code: var nc, err = nats.Connect(nats.
Read more >NATS and Docker - NATS Docs
The NATS server is provided as a Docker image on Docker Hub that you can run using the Docker daemon. The NATS server...
Read more >NATS and Docker - NATS Docs
The NATS server is provided as a Docker image on Docker Hub that you can run using the Docker daemon. The NATS server...
Read more >arm32v6/nats-streaming - Docker Image
nats -streaming is a high performance streaming server for the NATS Messaging ... You can however use v0.15.0+ and connect it to existing...
Read more >High availability with nats-streaming-server (clustering)
I wanted to set up a high available nats-streaming-server cluster, but couldn't find a “quick” guide on how to do it.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oops, turns out the cluster log path can’t be the same for all three containers when they’re running locally! I guess that’s why those commands were working fine from a windows command prompt but not from the docker containers.
The streaming client connects fine now that the cluster is properly configured.
If anyone sees this and just wants a quick simple local setup using docker containers here are the commands
Streaming client works like this:
Thanks for the responses!
With the
--cluster_raft_logging
I’m seeing a lot of theseThis probably isn’t a client issue anymore, is it…
Do my Docker run commands look correct?