Philly G
Philly G

Reputation: 21

How can my client from another device access my docker nats-server?

I have a docker nats-server running in WSL.

docker run -d -p 4222:4222 -p 6222:6222 -p 8222:8222 --name my-nats-container nats:latest

When I run my client on my host machine, it connects fine.

But what if my client is on another device? I'm trying to connect to the http server on port 8222 from the other device and I'm unable to connect to it. Or telnet into with port 4222.

What am I missing to broadcast my nats-server throughout my network?

What ip address should my client use to connect to my nats-server? It should be my host ip.

Expecting to connect to my dockerized nats-server from another machine.

Update: When I run the nats-server.exe (without docker) I connect fine using the ip address of the host. It's when I use it as a docker it does not connect.

Update #2: It seems my WSL has its own IP and my host is another IP. I looked at maybe doing a portproxy to be able to forward any HostIP connects towards a WSL connect. Is there no other way?

Upvotes: 0

Views: 234

Answers (1)

Dulan Dissanayake
Dulan Dissanayake

Reputation: 793

If your client is in the same network (wifi) as the nats docker host, then you have to use the docker host private ip for nats connection.

Ex:

  • Docker host (nats server) ip is 192.168.0.4 [check your private ip from command line using ipconfig]
  • Client connecting to nats server ip is 192.168.0.6

Then you your client should be able to connect to docker host without any issues

Upvotes: 0

Related Questions