快速参考
-
由……维护
NATS 项目 -
何处获取帮助:
Docker 社区 Slack、服务器故障、Unix & Linux 或 Stack Overflow
支持的标签及相应的 Dockerfile 链接
(见常见问题解答中“‘共享’和‘简单’标签之间的区别是什么?”)
简单标签
-
2.10.20-scratch,2.10-scratch,2-scratch,scratch,2.10.20-linux,2.10-linux,2-linux,linux -
2.10.20-nanoserver-1809,2.10-nanoserver-1809,2-nanoserver-1809,nanoserver-1809 -
2.9.25-alpine3.18,2.9-alpine3.18,2.9.25-alpine,2.9-alpine
共享标签
-
2.10.20,2.10,2,latest:2.10.20-scratch2.10.20-nanoserver-1809-
2.10.20-windowsservercore,2.10-windowsservercore,2-windowsservercore,windowsservercore: -
2.10.20-nanoserver,2.10-nanoserver,2-nanoserver,nanoserver: -
2.9.25,2.9: -
2.9.25-windowsservercore,2.9-windowsservercore: -
2.9.25-nanoserver,2.9-nanoserver:
快速参考(续)
-
支持的架构:(更多信息)
amd64,arm32v6,arm32v7,arm64v8,ppc64le,s390x,windows-amd64 -
已发布的图像工件详细信息:
仓库信息 仓库的repos/nats/目录(历史)
(图像元数据、传输大小等) -
图像更新:
官方镜像仓库的library/nats标签
官方镜像仓库的library/nats文件(历史记录) -
此描述的来源:
文档库的nats/目录(历史)
NATS:一个高性能的云原生消息系统。

nats 是 NATS 消息系统的高性能服务器。
示例用法
# 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.
$ docker run -d --name nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats
[INF] Starting nats-server
[INF] Version: 2.9.8
[INF] Git: [60e335a]
[INF] Cluster: my_cluster
[INF] Name: NB3YN6SPZF6MWTLPGYLRE2AD5VVWSW443RO43YR5GC62I463QPYGOL5C
[INF] ID: NB3YN6SPZF6MWTLPGYLRE2AD5VVWSW443RO43YR5GC62I463QPYGOL5C
[INF] Using configuration file: /etc/nats/nats-server.conf
[INF] Starting http monitor on 0.0.0.0:8222
[INF] Listening for client connections on 0.0.0.0:4222
[INF] Server is ready
[INF] Cluster name is my_cluster
[INF] Listening for route connections on 0.0.0.0:6222
...
# To run a second server and cluster them together..
# Note that since you are passing arguments, this overrides the CMD section
# of the Dockerfile, so you need to pass all arguments, including the
# config file.
$ docker run -d --name=nats-2 --link nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats -c /etc/nats/nats-server.conf --routes=nats-route://ruser:T0pS3cr3t@nats-main:6222
# If you want to verify the routes are connected, try this instead:
$ docker run -d --name=nats-2 --link nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats -c /etc/nats/nats-server.conf --routes=nats-route://ruser:T0pS3cr3t@nats-main:6222 -DV
[INF] Starting nats-server
[INF] Version: 2.9.8
[INF] Git: [60e335a]
[DBG] Go build: go1.19.3
[INF] Cluster: my_cluster
[INF] Name: NDFNAUTD4RKS2O7CMKMDMTV3DW5NIKFCQDDMXW2A5YXLUZWWX7RYFCKB
[INF] ID: NDFNAUTD4RKS2O7CMKMDMTV3DW5NIKFCQDDMXW2A5YXLUZWWX7RYFCKB
[INF] Using configuration file: /etc/nats/nats-server.conf
[DBG] Created system account: "$SYS"
[INF] Starting http monitor on 0.0.0.0:8222
[INF] Listening for client connections on 0.0.0.0:4222
[DBG] Get non local IPs for "0.0.0.0"
[DBG] ip=172.17.0.2
[INF] Server is ready
[DBG] maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
[INF] Cluster name is my_cluster
[INF] Listening for route connections on 0.0.0.0:6222
[DBG] Trying to connect to route on nats-main:6222 (172.17.0.3:6222)
[DBG] 172.17.0.3:6222 - rid:4 - Route connect msg sent
[INF] 172.17.0.3:6222 - rid:4 - Route connection created
[DBG] 172.17.0.3:6222 - rid:4 - Registering remote route "NDQAU6HVD44TI2X5R2QRYJEIQR3MMHCFTW2BTSXBILBOZHJ4Z7AR7GGR"
[DBG] 172.17.0.3:6222 - rid:4 - Sent local subscriptions to route
服务器将加载下面的配置文件。任何命令行标志都可以覆盖这些值。
默认配置文件
# Client port of 4222 on all interfaces
port: 4222
# HTTP monitoring port
monitor_port: 8222
# This is for clustering multiple servers together.
cluster {
# It is recommended to set a cluster name
name: "my_cluster"
# Route connections to be received on any interface on port 6222
port: 6222
# Routes are protected, so need to use them with --routes flag
# e.g. --routes=nats-route://ruser:T0pS3cr3t@otherdockerhost:6222
authorization {
user: ruser
password: T0pS3cr3t
timeout: 2
}
# Routes are actively solicited and connected to from this server.
# This Docker image has none by default, but you can pass a
# flag to the nats-server docker image to create one to an existing server.
routes = []
}
命令行选项
Server Options:
-a, --addr, --net <host> Bind to host address (default: 0.0.0.0)
-p, --port <port> Use port for clients (default: 4222)
-n, --name
--server_name <server_name> Server name (default: auto)
-P, --pid <file> File to store PID
-m, --http_port <port> Use port for http monitoring
-ms,--https_port <port> Use port for https monitoring
-c, --config <file> Configuration file
-t Test configuration and exit
-sl,--signal <signal>[=<pid>] Send signal to nats-server process (stop, quit, reopen, reload)
pid> can be either a PID (e.g. 1) or the path to a PID file (e.g. /var/run/nats-server.pid)
--client_advertise <string> Client URL to advertise to other servers
--ports_file_dir <dir> Creates a ports file in the specified directory (<executable_name>_<pid>.ports).
Logging Options:
-l, --log <file> File to redirect log output
-T, --logtime Timestamp log entries (default: true)
-s, --syslog Log to syslog or windows event log
-r, --remote_syslog <addr> Syslog server addr (udp://localhost:514)
-D, --debug Enable debugging output
-V, --trace Trace the raw protocol
-VV Verbose trace (traces system account as well)
-DV Debug and trace
-DVV Debug and verbose trace (traces system account as well)
--log_size_limit <limit> Logfile size limit (default: auto)
--max_traced_msg_len <len> Maximum printable length for traced messages (default: unlimited)
JetStream Options:
-js, --jetstream Enable JetStream functionality
-sd, --store_dir <dir> Set the storage directory
Authorization Options:
--user <user> User required for connections
--pass <password> Password required for connections
--auth <token> Authorization token required for connections
TLS Options:
--tls Enable TLS, do not verify clients (default: false)
--tlscert <file> Server certificate file
--tlskey <file> Private key for server certificate
--tlsverify Enable TLS, verify client certificates
--tlscacert <file> Client certificate CA for verification
Cluster Options:
--routes <rurl-1, rurl-2> Routes to solicit and connect
--cluster <cluster-url> Cluster URL for solicited routes
--cluster_name <string> Cluster Name, if not set one will be dynamically generated
--no_advertise <bool> Do not advertise known cluster information to clients
--cluster_advertise <string> Cluster URL to advertise to other servers
--connect_retries <number> For implicit routes, number of connect retries
--cluster_listen <url> Cluster url from which members can solicit routes
Profiling Options:
--profile <port> Profiling HTTP port
Common Options:
-h, --help Show this message
-v, --version Show version
--help_tls TLS help
图像变体
nats 图像有多种类型,每种都针对特定的用例而设计。
nats:<version>
这是事实上的镜像。如果你不确定自己的需求是什么,你可能想要使用这个。它被设计既可用作一次性容器(挂载你的源代码并启动容器以启动你的应用程序),也可用作构建其他镜像的基础。
nats:<version>-alpine
此镜像基于流行的 Alpine Linux 项目,在 alpine 官方镜像中可用。Alpine Linux 比大多数发行版基础镜像小得多(约 5MB),因此通常会生成更精简的镜像。
当尽可能小的最终镜像大小是你主要关心的问题时,这个变体很有用。需要注意的主要警告是,它确实使用 musl libc 而不是 glibc 及其同类,所以软件通常会根据其对 libc 要求/假设的深度而遇到问题。有关可能出现的问题以及使用基于 Alpine 的镜像的一些优缺点比较的更多讨论,请参阅此 Hacker News 评论线程。
为了最小化镜像大小,在基于 Alpine 的镜像中包含额外的相关工具(例如 git 或 bash )是不常见的。使用此镜像作为基础,在你自己的 Dockerfile 中添加你需要的东西(如果你不熟悉,可查看 alpine 镜像描述以获取如何安装软件包的示例)。
nats:<version>-windowsservercore
此图像基于 Windows Server Core( microsoft/windowsservercore )。因此,它仅在该图像适用的地方起作用,例如 Windows 10 专业版/企业版(周年纪念版)或 Windows Server 2016。
有关如何在 Windows 上运行 Docker 的信息,请参阅 Microsoft 提供的相关“快速入门”指南:
许可证
查看此映像中包含的软件的许可证信息。
与所有 Docker 镜像一样,这些镜像可能还包含其他可能受其他许可证约束的软件(例如来自基础发行版的 Bash 等,以及所包含的主要软件的任何直接或间接依赖项)。
一些能够自动检测到的额外许可证信息可能会在 repo-info 存储库的 nats/ 目录中找到。
对于任何预构建镜像的使用,镜像用户有责任确保对此镜像的任何使用都符合其中包含的所有软件的任何相关许可证。