> For the complete documentation index, see [llms.txt](https://docs.viesus.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.viesus.com/reference/docker/nodejs.md).

# Docker for Node.js

{% hint style="info" %}
**Linux Only**

The VIESUS Node.js module is available on **Linux only**.
{% endhint %}

Containerizing the Node.js module follows the same foundation as the CLI Docker setup — the VIESUS `.deb` packages are installed inside the container, then the npm module is linked from the installed location.

***

## Prerequisites

* Docker Engine installed on the host
* NVIDIA Container Toolkit installed (for GPU support)
* VIESUS `.deb` packages (`.deb` files must be in your build context)

If you do not already have the NVIDIA Container Toolkit:

```bash
# Add NVIDIA Container Toolkit repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
  sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
```

***

## Build context

Prepare the directory you'll build from:

```powershell
viesus-node-docker/
├── Dockerfile
├── viesus-redist_<VERSION>_amd64.deb
├── viesus_<VERSION>_amd64.deb
├── viesus-license_<VERSION>_amd64.deb
├── package.json
├── server.js            # or your application entry point
├── worker.js
└── viesusini.json
```

***

## Dockerfile

```dockerfile
FROM nvidia/cuda:12.6.0-runtime-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive

# System dependencies
RUN apt-get update && apt-get install -y \
    curl \
    ca-certificates \
    && rm -rf /var/lib/apt/lists/*

# Install VIESUS packages
COPY viesus-redist_<VERSION>_amd64.deb \
     viesus_<VERSION>_amd64.deb \
     viesus-license_<VERSION>_amd64.deb /tmp/
RUN dpkg -i /tmp/viesus-redist_<VERSION>_amd64.deb \
            /tmp/viesus_<VERSION>_amd64.deb \
            /tmp/viesus-license_<VERSION>_amd64.deb && \
    apt-get install -f -y && \
    rm /tmp/*.deb

# Install Node.js 18
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - && \
    apt-get install -y nodejs && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install npm dependencies (including viesus native module)
COPY package.json ./
RUN npm install /usr/local/viesus/node-viesus && \
    npm install node-worker-threads-pool --save

# Copy application files
COPY worker.js server.js viesusini.json ./

EXPOSE 3000

ENV UV_THREADPOOL_SIZE=16

CMD ["node", "server.js"]
```

{% hint style="info" %}
The `nvidia/cuda` base image tag (`12.6.0-runtime-ubuntu22.04`) must match your host NVIDIA driver. Check the [NVIDIA Container Registry](https://catalog.ngc.nvidia.com/orgs/nvidia/containers/cuda) for available tags and replace `12.6.0` as needed.
{% endhint %}

***

## Build the image

```bash
docker build -t viesus-node:latest .
```

***

## Run the container

### CPU mode

```bash
docker run -d \
  --name viesus-node \
  -p 3000:3000 \
  -e VIESUS_GUID="your-guid-here" \
  -e UV_THREADPOOL_SIZE=16 \
  viesus-node:latest
```

### GPU mode

```bash
docker run -d \
  --name viesus-node \
  --gpus all \
  -p 3000:3000 \
  -e VIESUS_GUID="your-guid-here" \
  -e UV_THREADPOOL_SIZE=4 \
  viesus-node:latest
```

When using GPUs, set `UV_THREADPOOL_SIZE` to the number of GPUs, not the number of CPU cores. See [GPU Scaling](/reference/node.js-module/getting-started.md#scaling-to-multiple-gpus).

***

## Passing the GUID securely

Never hardcode the GUID in the Dockerfile or application code. Pass it at runtime:

```bash
# Directly
docker run -e VIESUS_GUID="your-guid-here" ...

# From an env file
docker run --env-file .env ...

# Docker secret (Swarm/Compose)
docker secret create viesus_guid ./guid.txt
```

Read the GUID in your application:

```js
const pool = new StaticPool({
  size: Number(process.env.UV_THREADPOOL_SIZE) || 4,
  task: './worker.js',
  workerData: process.env.VIESUS_GUID
});
```

***

## Docker Compose example

```yaml
version: '3.8'

services:
  viesus-node:
    build: .
    ports:
      - "3000:3000"
    environment:
      - VIESUS_GUID=${VIESUS_GUID}
      - UV_THREADPOOL_SIZE=16
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    restart: unless-stopped
```

Run with:

```bash
VIESUS_GUID="your-guid-here" docker-compose up -d
```

***

## Production considerations

<table><thead><tr><th width="174.800048828125">Topic</th><th>Recommendation</th></tr></thead><tbody><tr><td>Image size</td><td>Use multi-stage builds to reduce final image size; the CUDA runtime base is large</td></tr><tr><td>GUID security</td><td>Pass via environment variable or secret manager — never bake into the image</td></tr><tr><td>Graceful shutdown</td><td>Handle <code>SIGTERM</code> to allow in-flight requests to complete before the pool closes</td></tr><tr><td>Health check</td><td>Add a lightweight <code>GET /health</code> endpoint that returns 200; use it for readiness probes</td></tr><tr><td>Logging</td><td>Stream stdout/stderr — Docker captures it; ship to your log aggregator</td></tr><tr><td>GPU reservation</td><td>Use <code>--gpus all</code> or specify by device ID if only some GPUs should be used</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.viesus.com/reference/docker/nodejs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
