Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foofoodog/2fde8f578cd8d1edfa53e8eaab73fbd8 to your computer and use it in GitHub Desktop.
Save foofoodog/2fde8f578cd8d1edfa53e8eaab73fbd8 to your computer and use it in GitHub Desktop.
node-red with dashboard and mosquitto in alpine docker

node-red with dashboard and mosquitto in alpine docker

Cmd wrapper around docker commands to build and run an IoT dashboard kind of thing. Tries to do the right thing:

  • Create the image if it does not exist then run the container.
  • Run the container if it does not exist and the image does.
  • Start the container if it exists and is stopped.
Usage: node-red-local [clean]
    clean: Remove container and image to start from scratch. Note that all flows and dashboard items will be lost.
from alpine
workdir node_red
run apk update; \
apk add nodejs; \
apk add mosquitto; \
npm init -f; \
npm install node-red; \
npm install node-red-dashboard;
expose 1880 1883
cmd mosquitto -d; \
./node_modules/.bin/node-red;
[{"id":"525a1a3.d07f1e4","type":"tab","label":"MQQT Test","disabled":false,"info":""},{"id":"aea2398f.653398","type":"mqtt in","z":"525a1a3.d07f1e4","name":"","topic":"any/#","qos":"2","broker":"eb63cf65.8df11","x":290,"y":140,"wires":[["2a8a6988.9a5636","47c041d0.fa943"]]},{"id":"c014caa.afb5a38","type":"mqtt out","z":"525a1a3.d07f1e4","name":"","topic":"","qos":"","retain":"","broker":"eb63cf65.8df11","x":690,"y":240,"wires":[]},{"id":"2a8a6988.9a5636","type":"debug","z":"525a1a3.d07f1e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":630,"y":140,"wires":[]},{"id":"22416f5f.937db","type":"inject","z":"525a1a3.d07f1e4","name":"","topic":"any/timestamp","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":350,"y":240,"wires":[["c014caa.afb5a38"]]},{"id":"47c041d0.fa943","type":"ui_toast","z":"525a1a3.d07f1e4","position":"top right","displayTime":"3","highlight":"","outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":670,"y":180,"wires":[]},{"id":"eb63cf65.8df11","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]
@echo off
setlocal
set image=node-red-local
set ports=-p 1880:1880 -p 1883:1883
set admin_site=http://localhost:1880/
set dash_site=http://localhost:1880/ui/
if %1.==clean. goto :clean
rem no image so build and run it
docker image ls --format {{.Repository}} | find "%image%" > nul || goto :build
rem container is running
docker ps --format {{.Image}} | find "%image%" > nul && goto :running
rem container is stopped
docker ps -a --format {{.Image}} | find "%image%" > nul && goto :start
rem image is not in container
docker image ls --format {{.Repository}} | find "%image%" > nul && goto :run
goto :eof
:clean
docker stop %image%
docker rm %image%
docker image rm %image%
goto :eof
:build
echo building %image%
docker build -t %image% .
:run
echo running %image%
docker run -d -t --name %image% %ports% %image%
goto :running
:start
echo starting %image%
docker start %image% > nul
goto :running
:running
echo %image% is running
start %dash_site%
start %admin_site%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment