Building Docker Images for Reactor
These instructions are a work in progress, and written for those familiar with docker and building images, and I've got my hands full with feature coding and device support, so I will not troubleshoot custom container builds at this time.
DO NOT PUBLISH!
DO NOT publish your image to any repository. It is a violation of the Reactor Software Preview License Agreement to do so. The image you create is for your use alone and may not be disseminated or distributed.
Files and Prerequisites
You're going to need three files:
- A Reactor generic release archive, which you can download from the project's MantisBT bug tracker.
- A Dockerfile to build the image (see below).
- If you want to use docker-compose to run your image, a docker-compose.yaml file (see below).
You will also need to have docker installed, and if you wish, docker-compose (recommended).
File: Dockerfile
Here's a sample Dockerfile for building your image. You may need to change the base (in FROM
at the top) for your particular needs. Whatever changes you make, make sure you include nodejs version 14.15 or higher and npm.
FROM node:alpine
# Where Reactor lives in the container
ENV REACTOR_HOME="/opt/reactor"
# Container stores all variable data under /var/reactor
ENV REACTOR_DATA_PREFIX="/var/reactor"
# Default port
ENV PORT=8111
# Update node and npm (if you change FROM, you may need to adjust this)
RUN apk add --no-cache --update nodejs npm
# Creates directory if doesn't exist
WORKDIR ${REACTOR_HOME}
LABEL description="Reactor (Multi-Hub)"
LABEL version="###BUILDVERSION###"
LABEL copyright="Copyright (C) 2020-2022 Kedron Holdings LLC, All Rights Reserved"
LABEL cicd="reactor"
COPY reactor ./
RUN rm -rf node_modules && \
npm set progress=false && \
npm set depth 0 && \
npm install --loglevel error --no-save
WORKDIR ${REACTOR_DATA_PREFIX}
VOLUME ${REACTOR_DATA_PREFIX}
EXPOSE ${PORT}
STOPSIGNAL SIGTERM
HEALTHCHECK --interval=5m --timeout=15s CMD curl -f http://localhost:${PORT}/api/v1/alive || exit 1
WORKDIR ${REACTOR_HOME}
CMD ["node", "app.js"]
File: docker-compose.yaml
This is a prototypical docker-compose.yaml
file. You will need to modify the entry in the volumes
section to map the /var/reactor
directory inside the container to a directory in a writable filesystem where your configuration files and logs can be stored. This allows you to update the docker image without losing your configuration and rule data. The syntax of this line is your-directorypath:/var/reactor
. Make sure you do not lose the :/var/reactor
at the end of the line.
# Multi-System Reactor template docker-compose.yml (version 22042)
#
# Change the lines indicated by "DO"...
#
version: '3'
services:
reactor:
container_name: reactor
environment:
# DO change the TZ: line to set your local time zone.
# See valid TZ list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
TZ: America/New_York
#
# DO NOT change this path. Your directory location is in "source" below.
REACTOR_DATA_PREFIX: /var/reactor
# DO change the image below to the one you are using, if necessary.
image: toggledbits/reactor:latest-generic-amd64
restart: "always"
expose:
- 8111
ports:
- 8111:8111
volumes:
# DO change the /home/username/reactor below to the directory you created for
# your local data; DO NOT change the /var/reactor part
- /home/username/reactor:/var/reactor
- /etc/localtime:/etc/localtime:ro
tmpfs: /tmp
Building the Image
-
Create a clean, new directory in which to do the build, and make it your current working directory.
-
Unarchive the Reactor release archive you will use for the build:
tar -x -v -f reactor-0.1-xxxxx-zzzzzzzz.tar.gz
You should now have a
reactor
subdirectory in your working directory. -
Copy the above Dockerfile contents to a file called
Dockerfile-orig
. Make any changes to it you need to before continuing. -
Stamp the docker file with the release version (on the
LABEL version=
line) and save it to a new file. You can do this by hand with your favorite text editor, or use thebash
command shown here. The release version can be found in a file calledbuildstamp
in thereactor
subdirectory:sed "s/###BUILDVERSION###/$(head -1 reactor/buildstamp)/" <Dockerfile-orig >/tmp/dockerfile
-
Build the image using the stamped dockerfile:
docker build -f /tmp/dockerfile -t toggledbits/reactor .
-
Before starting your new image/container, make sure you have created the directory that will hold the Reactor configuration, logs, and data. This is the directory named in the
volumes
section ofdocker-compose.yaml
for the container's mount point/var/reactor
. When the Reactor "Getting Started" instructions and other references direct you to either thelogs
orconfig
directories, this is the parent directory in which you will find them. -
At this point, you are ready to create and start your Reactor docker container. If you are using docker-compose:
docker-compose up -d
DO NOT PUBLISH!
DO NOT publish your image to any repository. It is a violation of the Reactor Software License Agreement to do so. The image you create is for your use alone and may not be disseminated or distributed.
Updated: 2022-May-24