Skip to content

Instantly share code, notes, and snippets.

@Scarysize
Last active January 5, 2017 21:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Scarysize/26dec1a169697c2aecbaf276b4775f5b to your computer and use it in GitHub Desktop.
Save Scarysize/26dec1a169697c2aecbaf276b4775f5b to your computer and use it in GitHub Desktop.

Build the docker image and start the container.

Start Xvfb in the container via

$ /etc/init.d/xvfb start

Run Chrome with working WebGL in kiosk mode

$ google-chrome \
  --no-first-run \
  --user-data-dir=/tmp/chrome \
  --no-sandbox \
  --enable-logging=stderr \
  --use-gl=osmesa \
  --app=<some-url>

Open another shell into the container and take a screenshot:

$ import -window root screenshot.png

😎 Profit.

#
# Ubuntu Dockerfile
#
# https://github.com/dockerfile/ubuntu
#
# Pull base image.
FROM ubuntu:16.04
ADD xvfb /etc/init.d/xvfb
# Install.
RUN \
sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list && \
apt-get update && \
apt-get -y upgrade && \
apt-get install -y wget && \
# Chrome PPA
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' && \
apt-get update && \
apt-get install -y google-chrome-stable && \
# Virtual display
apt-get install -y xvfb && \
# OpenGL implementation for for Chrome
apt-get install -y libosmesa6 && \
# ImageMagick for taking screenshots
apt-get install -y imagemagick && \
# Link Mesa driver
ln -s /usr/lib/x86_64-linux-gnu/libOSMesa.so.6 /opt/google/chrome/libosmesa.so && \
# Make Xvfb daemon script executable
chmod +x /etc/init.d/xvfb
ENV HOME /root
# Export the virtual display Xvfb creates
ENV DISPLAY :1
# Define default command.
CMD ["bash"]
XVFB=/usr/bin/Xvfb
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
stop)
echo -n "Stopping virtual X frame buffer: Xvfb"
start-stop-daemon --stop --quiet --pidfile $PIDFILE
echo "."
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment