# NATS

## Reference Links

| Description      | URL                                  |
| ---------------- | ------------------------------------ |
| Official website | <https://nats.io/>                   |
| DockerHub image  | <https://hub.docker.com/_/nats>      |
| NATS Go SDK      | <https://github.com/nats-io/nats.go> |
| NATS JS SDK      | <https://github.com/nats-io/nats.js> |
| NATS Python SDK  | <https://github.com/nats-io/nats.py> |
| NKeys repository | <https://github.com/nats-io/nkeys>   |
| NATS CLI tool    | <https://github.com/nats-io/natscli> |

## Configuration

### NKey generation

```makefile
nats-nkey:
	nk -gen user -pubout
```

### Server

This file should be available on the system running NATS. NATS should be started using the `--config` or `-c` flag pointing to the path of this file (eg. `nats-server -c /path/to/this.conf`

```properties
accounts: {
  $SYS: {
    users: [
      # generate using `nk-gen user -pubout`
      {nkey: "..."},
    ]
  }
}

authorization: {
  users: [
    # generate using `nk-gen user -pubout`
    {nkey: "..."},
  ]
}

cluster: {
  name: "example"
}

jetstream: {
  max_memory_store: 2GB
  max_file_store: 8GB
}
```

## Docker

### Image

{% embed url="<https://hub.docker.com/_/nats>" %}

### Compose&#x20;

The following starts NATS using the leanest image base (`scratch`) and with JetStream enabled:

<pre class="language-yaml"><code class="lang-yaml"><strong>version: "3.7"
</strong>services:
  nats: # access with `nats server info`
    # image reference: https://hub.docker.com/_/nats
    image: library/nats:2.9.20-scratch
    entrypoint:
      - /nats-server
      - -js
      - -c
      - /etc/nats/server.conf
    ports:
      - "4222:4222"
      # # enable as needed
      # - "6222:6222"
      # - "8222:8222"
    network_mode: host
    volumes:
      - ./.data/nats/config/server.conf:/etc/nats/server.conf
</code></pre>
