How to change nats port locally and in the nats container?

325 views Asked by At

I am quite new in nats and jetstream. I really appreciate any help :). My question is that how I can create a nats container with nondefault port which means not 4222. I was trying to create docker container for nats server with port 4222 like below:

docker pull nats:latest
docker run -d -p 4225:4225 nats -js

now the container is running with port 4225. Fine right? But I cannot connect to this nats server via powershell. As a simple example when I tried to create a subscription like below:

nats sub test

I got this:

nats: error: dial tcp 127.0.0.1:4222: i/o timeout

I am wondering why the terminal is trying to connect via 127.0.0.1:4222 and not 127.0.0.1:4225 ? Am I actually missing something?

1

There are 1 answers

0
shriek On

It's almost a year late but I figured I'd reply in case someone else runs into this later.
For non-default ports pass -p flag.
e.g.

docker run nats -js -p 4225

Now your docker command should be able to map host-port to container-port just fine with:

docker run -d -p 4225:4225 nats -js -p 4225