Node connector with docker compose

This example Dockerfile packages our example Node Fluvio project into a connector image.

 

Dockerfile

FROM node:16

# Run as the `fluvio` user instead of root
ENV USER=fluvio
RUN useradd --create-home "$USER"
USER $USER
WORKDIR /home/fluvio 

# Copy your Node project
COPY --chown=$USER:$USER *.ts ./
COPY --chown=$USER:$USER *.json ./

# Install dependencies
RUN mkdir -p ~/.local/bin && \
   npm config set prefix '~/.local/' && \
   npm init -y && \
   npm install -D typescript ts-node @types/node && \
   npm install -S @fluvio/client

# Run your Node project
CMD npx ts-node example.ts

This docker-compose.yml used with docker compose CLI starts our previously built connector image as a local connector

 

docker-compose.yml

version: "3"
services:
 example:
   build: .
   network_mode: "host"
   volumes:
     - $HOME/.fluvio/config:/home/fluvio/.fluvio/config:ro
     - $HOME/.kube:/home/fluvio/.kube:ro
 

Run example

$ docker compose build
$ docker compose run example
 

Example output

[...]
Connecting client to fluvio
Connecting client to fluvio
Creating topic
read from the end
Key=example-key, Value=Hello World!  - Time is Thu Nov 10 2022 02:28:01 GMT+0000 (Coordinated Universal Time)
[...]