How to run multiple nat instances
fxfactorial opened this issue · 3 comments
I am trying to use multiple nats instances but it seems that 4222
is some magic port.
Is there an env
var that can control what port NATs will run on
@fxfactorial Maybe I am not understanding what you are asking, but it may be as simple as you providing the ports that you want the server to listen to and docker to export. From the docker hub page, here is the info:
# Run a NATS server
# Each server exposes multiple ports
# 4222 is for clients.
# 8222 is an HTTP management port for information reporting.
# 6222 is a routing port for clustering.
#
# To actually publish the ports when running the container, use the Docker port mapping
# flag "docker run -p <hostport>:<containerport>" to publish and map one or more ports,
# or the -P flag to publish all exposed ports and map them to high-order ports.
#
# This should not be confused with the NATS Server own -p parameter.
# For instance, to run the NATS Server and have it listen on port 4444,
# you would have to run like this:
#
# docker run -p 4444:4444 nats -p 4444
#
# Or, if you want to publish the port 4444 as a different port, for example 5555:
#
# docker run -p 5555:4444 nats -p 4444
#
# Check "docker run" for more information.
Let me know if that helps.
Sorry, I meant more like an example in docker-compose yaml file and with each nats working on a different port. I notice gnats needs a config and didn't see how to tell gnats what port to use just from a docker compose yaml file.
@fxfactorial to create a NATS cluster locally using docker compose you would have to create an entry for each one of the nats containers. Here is an example from the community where a NATS cluster is created using Docker compose: https://github.com/bmcstdio/docker-compose-nats-cluster/blob/master/docker-compose.yaml
version: "3"
networks:
main:
driver: bridge
ipam:
config:
- subnet: 172.25.255.0/24
driver: default
services:
nats-1:
command:
- "-p"
- "4222"
- "-cluster"
- "nats://172.25.255.10:6222"
expose:
- "6222"
image: "nats:1.2.0"
networks:
main:
ipv4_address: "172.25.255.10"
nats-2:
command:
- "-p"
- "4222"
- "-cluster"
- "nats://172.25.255.20:6222"
- "-routes"
- "nats://172.25.255.10:6222"
image: "nats:1.2.0"
expose:
- "6222"
networks:
main:
ipv4_address: "172.25.255.20"
nats-3:
command:
- "-p"
- "4222"
- "-cluster"
- "nats://172.25.255.30:6222"
- "-routes"
- "nats://172.25.255.10:6222"
image: "nats:1.2.0"
expose:
- "6222"
networks:
main:
ipv4_address: "172.25.255.30"