Skip to content

Instantly share code, notes, and snippets.

@stephenhouser
Last active December 28, 2018 15:52
Show Gist options
  • Save stephenhouser/56bf0536cc8e47bdef6f4d4628db52c9 to your computer and use it in GitHub Desktop.
Save stephenhouser/56bf0536cc8e47bdef6f4d4628db52c9 to your computer and use it in GitHub Desktop.
Nightmare Browser Node Red Container with remote X display (or headless) on macOS

Nightmare Browser Node Red Container with remote X display (or headless) on macOS

Adapted from code node-red-contrib-browser issue #5

Docker image is built with (in case I forget, which I often do):

docker build -t nb-docker .
#!/bin/bash
# To show on XQuartz on macOS
# https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/
ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
xhost + $ip
docker run -it \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e DISPLAY=$ip:0 \
-p 1880:1880 \
--name nb-docker \
nb-docker
FROM nodered/node-red-docker:v8
# Switch back to root user to install packages and configure entrypoint
USER root
RUN apt-get update && apt-get install -y \
xvfb \
x11-xkb-utils \
xfonts-100dpi \
xfonts-75dpi \
xfonts-scalable \
xfonts-cyrillic \
x11-apps \
clang \
libdbus-1-dev \
libgtk2.0-dev \
libnotify-dev \
libgnome-keyring-dev \
libgconf2-dev \
libasound2-dev \
libcap-dev \
libcups2-dev \
libxtst-dev \
libxss1 \
libnss3-dev \
gcc-multilib \
g++-multilib \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
RUN mkdir -m 1777 /tmp/.X11-unix
# Switch back to node-red user to install the nbrowser module and run as non-root user
USER node-red
RUN npm install node-red-contrib-nbrowser node-red-contrib-fs-ops node-red-contrib-credentials
ENV DEBUG=nightmare
CMD ["npm", "start", "--", "--userDir", "/data"]
#!/usr/bin/env bash
set -e
# Start Xvfb
if [ -z ${DISPLAY+x} ]
then
Xvfb -ac -screen scrn 1280x2000x24 :9.0 &
export DISPLAY=:9.0
fi
exec "$@"
#!/bin/bash
export DISPLAY=
docker run -it \
-p 1880:1880 \
--name headless \
nb-docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment