Skip to content
kevincw01 edited this page Nov 4, 2024 · 6 revisions

Pre-built Docker images

If you just want to test it out with Docker and your RS-485 adapter is on the default port /dev/ttyUSB0

$ docker run --rm -it --group-add dialout -p 4200:4200 --device /dev/ttyUSB0 msmi/nodejs-poolcontroller

Docker Compose examples

For a more permanent install, use a docker compose file.

Server-only minimal example:

docker-compose.yml

services:
  poolcontroller:
    group_add:
      - dialout
    devices:
      - /dev/ttyUSB0
    ports:
      - "4200:4200"
    image: msmi/nodejs-poolcontroller

Server-only with access to the config and some useful directories:

services:
  poolcontroller:
    container_name: poolcontroller
    restart: always
    group_add:
      - dialout
    devices:
      - /dev/ttyUSB0
    ports:
      - "4200:4200"
    volumes:
      - /data/poolcontroller/data:/app/data
      - /data/poolcontroller/logs:/app/logs
      - type: bind
        source: /data/poolcontroller/config.json
        target: /app/config.json
    image: msmi/nodejs-poolcontroller

Server and dashPanel client:

services:
  poolcontroller:
    container_name: poolcontroller
    restart: always
    group_add:
      - dialout
    devices:
      - /dev/ttyUSB0
    ports:
      - "4200:4200"
    volumes:
      - /data/poolcontroller/data:/app/data
      - type: bind
        source: /data/poolcontroller/config.json
        target: /app/config.json
    image: msmi/nodejs-poolcontroller
  poolcontroller-dashpanel:
    restart: always
    container_name: poolcontroller-dashpanel
    ports:
      - "5150:5150"
    volumes:
      - type: bind
        source: /data/poolcontroller-dashpanel/config.json
        target: /app/config.json
    image: msmi/nodejs-poolcontroller-dashpanel
    depends_on:
      - poolcontroller

Docker socat example:

services:
  poolcontroller:
    container_name: poolcontroller
    restart: always
    ports:
      - "4200:4200"
    volumes:
      - /data/poolcontroller/data:/app/data
      - type: bind
        source: /data/poolcontroller/config.json
        target: /app/config.json
    image: msmi/nodejs-poolcontroller
  socat:
    command: tcp-listen:9801,fork,reuseaddr file:/dev/ttyUSB0,b9600,raw,echo=0
    container_name: socat
    restart: always
    ports:
      - "9801:9801"
    devices:
      - /dev/ttyUSB0
    image: alpine/socat

Docker ReadyNAS example:

services:
  poolcontroller:
    container_name: poolcontroller
    restart: always
    group_add:
      - dialout
    devices:
      - /dev/ttyUSB0
    ports:
      - "4200:4200"
    image: msmi/nodejs-poolcontroller:7.6.1
  poolcontroller-dashpanel:
    restart: always
    container_name: poolcontroller-dashpanel
    ports:
      - "5150:5150"
    image: msmi/nodejs-poolcontroller-dashpanel:7.6.1
    depends_on:
      - poolcontroller

Socat is useful if you'd like to occasionally run from somewhere else, or not using a Docker container, for testing or development. It's very stable.

Docker serial port access

You must specify the serial device in the docker-compose file or with docker run. Additionally, most linux base images will require the user to be in the dialout group for access to the serial port.

There are many ways to do this.

group_add:
  - dialout

is probably the safest. Beware that group_add existed in the v2 compose spec, but was removed in v3. It is now back, but you must have docker-compose 1.27.0+ and have Docker Engine 19.03.0+

If you have a v3 docker-compose file, then next easiest way is to include user: "node:dialout".

Both of these avoid either running as root or using a --priviledged container.

Notes

To update to the latest images:

$ docker compose pull && docker compose up -d

If you're running without volumes and need to get a copy of the current config:

$ docker exec -it poolcontroller cat /app/config.json > config.json

Connect to the running container:

$ docker exec -it poolcontroller sh

To get a specific version, just append it to the image name, for example:

$ docker pull msmi/nodejs-poolcontroller:7.6.1

All available tags for pre-built images.

Pre-built images are multi-architecture (arm/v6, arm/v7, arm64 and amd64), which should cover most cases. They are based on node-alpine and are reasonably small.

Build a customized Docker image

If you would like to build for another architecture or add something to the image, you can build your own using the Dockerfile as a template or write your own.

Add a package to the Dockerfile template:

$ git clone https://github.com/tagyoureit/nodejs-poolController
$ cd nodejs-poolController
$ cp Dockerfile ../Dockerfile.mine
$ vi ../Dockerfile.mine

Add bash and bash-completion packages:

FROM node:lts-alpine AS build
RUN apk add --no-cache make gcc g++ python linux-headers udev tzdata
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm ci --production

FROM node:lts-alpine as prod
# add additional packages here
RUN apk add --no-cache bash bash-completion 
RUN mkdir /app && chown node:node /app
WORKDIR /app
COPY --chown=node:node --from=build /app .
USER node
ENV NODE_ENV=production
ENTRYPOINT ["node", "dist/app.js"]

Then build it using whatever tag you like:

$ docker build --tag mynjspc --file ../Dockerfile.mine .

If you wanted a Debian-based image with the latest version of node (this image will be quite large):

FROM node:current AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm ci --production

FROM node:current as prod
RUN mkdir /app && chown node:node /app
WORKDIR /app
COPY --chown=node:node --from=build /app .
USER node
ENV NODE_ENV=production
ENTRYPOINT ["node", "dist/app.js"]

Or maybe a smaller Debian-based image with latest LTS version of node, but with some additional packages (slim doesn't include much by design):

FROM node:lts-slim AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
RUN npm ci --production

FROM node:lts-slim as prod
RUN apt-get update && apt-get install -y procps iproute2 zsh && rm -rf /var/lib/apt/lists/*
RUN mkdir /app && chown node:node /app
WORKDIR /app
COPY --chown=node:node --from=build /app .
USER node
ENV NODE_ENV=production
ENTRYPOINT ["node", "dist/app.js"]

You will need to update your git repo and rebuild your image to get the latest changes to nodejs-poolcontroller.

$ git pull
$ docker build --tag mynjspc --file ../Dockerfile.mine .
$ docker compose up -d