From 82dd0d7d1e1310b7daa0e36aeabb692618a5d932 Mon Sep 17 00:00:00 2001 From: Frank Carey Date: Fri, 30 Dec 2016 13:05:41 -0500 Subject: [PATCH 1/2] Issue #22: Get Docker image working with OpenGL and VNC. * Creates an Ubuntu 14.04, tightvnc, bazel image with all the dependencies for building and running lab. * Does an initial compile using 'bazel build :deepmind_lab.so --define headless=osmesa' * Run headless with 'bazel run :random_agent --define headless=osmesa' Issues: * OpenGL currently doesn't work properly for some reason, so running the non-headless version doesn't work. See https://ubuntuforums.org/archive/index.php/t-2257096.html --- .dockerignore | 2 ++ Dockerfile | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ vnc.sh | 6 ++++ 3 files changed, 89 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 vnc.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..acf05c7cf --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +docs +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..080d463c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,81 @@ +FROM kaixhin/vnc + +MAINTAINER fcarey@gmail.com + +RUN apt-get update && apt-get install -y \ + curl \ + zip \ + unzip \ + software-properties-common \ + python-software-properties && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# We need to add a custom PPA to pick up JDK8, since trusty doesn't +# have an openjdk8 backport. openjdk-r is maintained by a reliable contributor: +# Matthias Klose (https://launchpad.net/~doko). It will do until +# we either update the base image beyond 14.04 or openjdk-8 is +# finally backported to trusty; see e.g. +# https://bugs.launchpad.net/trusty-backports/+bug/1368094 +RUN add-apt-repository -y ppa:openjdk-r/ppa && \ + apt-get update && \ + apt-get install -y openjdk-8-jdk openjdk-8-jre-headless && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + which java && \ + java -version && \ + update-ca-certificates -f + +# Running bazel inside a `docker build` command causes trouble, cf: +# https://github.com/bazelbuild/bazel/issues/134 +# The easiest solution is to set up a bazelrc file forcing --batch. +# RUN echo "startup --batch" >>/root/.bazelrc +# Similarly, we need to workaround sandboxing issues: +# https://github.com/bazelbuild/bazel/issues/418 +# RUN echo "build --spawn_strategy=standalone --genrule_strategy=standalone" \ +# >>/root/.bazelrc +# ENV BAZELRC /root/.bazelrc +# Install the most recent bazel release. +ENV BAZEL_VERSION 0.4.3 +RUN mkdir /bazel && \ + cd /bazel && \ + curl -fSsL -O https://github.com/bazelbuild/bazel/releases/download/$BAZEL_VERSION/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + curl -fSsL -o /bazel/LICENSE.txt https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE.txt && \ + chmod +x bazel-*.sh && \ + ./bazel-$BAZEL_VERSION-installer-linux-x86_64.sh && \ + cd / && \ + rm -f /bazel/bazel-$BAZEL_VERSION-installer-linux-x86_64.sh + +# Install deepmind-lab dependencies +RUN apt-get update && apt-get install -y \ + lua5.1 \ + liblua5.1-0-dev \ + libffi-dev \ + gettext \ + freeglut3-dev \ + libsdl2-dev \ + libosmesa6-dev \ + python-dev \ + python-numpy \ + realpath \ + build-essential + +#Enable RANDR option for vnc server. +COPY ./vnc.sh /opt/vnc.sh + +# Set the default X11 Display. +ENV DISPLAY :1 + +ENV lab_dir /lab +RUN mkdir /$lab_dir +COPY . /$lab_dir +WORKDIR $lab_dir + +RUN bazel build :deepmind_lab.so --define headless=osmesa + +# RUN bazel run :python_module_test --define headless=osmesa + +#RUN bazel run :random_agent --define headless=false + + + diff --git a/vnc.sh b/vnc.sh new file mode 100644 index 000000000..24841692a --- /dev/null +++ b/vnc.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Remove VNC lock (if process already killed) +rm /tmp/.X1-lock /tmp/.X11-unix/X1 +# Run VNC server with tail in the foreground +vncserver :1 -randr -geometry 1280x800 -depth 24 && tail -F /root/.vnc/*.log From f25f64228c0edfeefa2fec696c6d6096c50eade3 Mon Sep 17 00:00:00 2001 From: Frank Carey Date: Thu, 9 Feb 2017 03:37:08 -0500 Subject: [PATCH 2/2] Issue #22: Create a Docker image. * After much debugging, it seems xvfb (virtual frame buffer) needed to be implemented to get opengl working properly. * Switched to using our own from-stratch Dockerfile based on Ubuntu 14.04 * Switched to x11vnc instead of tightvnc since tightvnc didn't seem to work, but not sure if that's still an issue or not. * Added lots of documentation around the various settings used. * Using fluxbox instead of lxdm because it was lighter weight. --- .docker/startup.sh | 33 +++++++++++++++++++ Dockerfile | 81 ++++++++++++++++++++++++++++++---------------- vnc.sh | 6 ---- 3 files changed, 86 insertions(+), 34 deletions(-) create mode 100644 .docker/startup.sh delete mode 100644 vnc.sh diff --git a/.docker/startup.sh b/.docker/startup.sh new file mode 100644 index 000000000..c4a1f1fec --- /dev/null +++ b/.docker/startup.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Remove VNC lock (if process already killed) +rm -f /tmp/.X1-lock /tmp/.X11-unix/X1 + +# Set the DISPLAY that will be used by default. Makes lab show up in our xvfb display +export DISPLAY=:1 + +# Start the X virtual frame buffer which uses memory instead of an actual device. +# Allows lab to be run headless. +Xvfb "$DISPLAY" -screen 0 "$XVFB_RESOLUTION" & + +# Run a lightweight Window Manager (fluxbox is smaller than lxdm, gnome, unity, kde, etc) +# (pretty sure this is required.) +fluxbox & + +# Run the x11vnc server +# Explanation of options: +# -display : This needs to match the xvfb display number +# -passwd : Use the password from an ENV var here instead of using ~/.vnc/passwd +# -o : Specifies where to send the log output. +# -noipv6 : Skip trying to serve vnc on ipv6 (avoids warnings) +# -bg : Run in the background +# -forever : Don't die when the first user disconnects from vnc (which is the default) +# -N : Makes it use port 5900+N where N is the display.. so 5901. (default is 5900) +x11vnc \ + -display "$DISPLAY" \ + -passwd "$VNC_PASSWORD" \ + -o /dev/stderr \ + -noipv6 \ + -bg \ + -forever \ + -N diff --git a/Dockerfile b/Dockerfile index 080d463c4..5f38e5c92 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,29 @@ -FROM kaixhin/vnc +FROM ubuntu:14.04 MAINTAINER fcarey@gmail.com +# Temporarily shut up warnings. +ENV DISPLAY :0 +ENV TERM xterm + +# Basic Dependencies RUN apt-get update && apt-get install -y \ curl \ zip \ unzip \ software-properties-common \ python-software-properties && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Dependencies for vnc setup. +RUN apt-get update && apt-get install -y \ + xvfb \ + fluxbox \ + x11vnc && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + # We need to add a custom PPA to pick up JDK8, since trusty doesn't # have an openjdk8 backport. openjdk-r is maintained by a reliable contributor: @@ -18,13 +32,14 @@ RUN apt-get update && apt-get install -y \ # finally backported to trusty; see e.g. # https://bugs.launchpad.net/trusty-backports/+bug/1368094 RUN add-apt-repository -y ppa:openjdk-r/ppa && \ - apt-get update && \ - apt-get install -y openjdk-8-jdk openjdk-8-jre-headless && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* && \ - which java && \ - java -version && \ - update-ca-certificates -f + apt-get update && apt-get install -y \ + openjdk-8-jdk \ + openjdk-8-jre-headless && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* && \ + which java && \ + java -version && \ + update-ca-certificates -f # Running bazel inside a `docker build` command causes trouble, cf: # https://github.com/bazelbuild/bazel/issues/134 @@ -48,34 +63,44 @@ RUN mkdir /bazel && \ # Install deepmind-lab dependencies RUN apt-get update && apt-get install -y \ - lua5.1 \ - liblua5.1-0-dev \ - libffi-dev \ - gettext \ - freeglut3-dev \ - libsdl2-dev \ - libosmesa6-dev \ - python-dev \ - python-numpy \ - realpath \ - build-essential + lua5.1 \ + liblua5.1-0-dev \ + libffi-dev \ + gettext \ + freeglut3-dev \ + libsdl2-dev \ + libosmesa6-dev \ + python-dev \ + python-numpy \ + realpath \ + build-essential && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* -#Enable RANDR option for vnc server. -COPY ./vnc.sh /opt/vnc.sh # Set the default X11 Display. ENV DISPLAY :1 +ENV VNC_PASSWORD=password +ENV XVFB_RESOLUTION=800x600x16 +# Set up deepmind-lab folder and copy in the code. ENV lab_dir /lab RUN mkdir /$lab_dir COPY . /$lab_dir WORKDIR $lab_dir -RUN bazel build :deepmind_lab.so --define headless=osmesa - -# RUN bazel run :python_module_test --define headless=osmesa - -#RUN bazel run :random_agent --define headless=false +# Run an actual (headless) build since this should make subsequent builds much faster. +# Alternative commands based on the Documentation: +# RUN bazel run :random_agent --define headless=false +# RUN bazel build :deepmind_lab.so --define headless=osmesa +RUN bazel run :python_module_test --define headless=osmesa +# This port is the default for connecting to VNC display :1 +EXPOSE 5901 +# Copy VNC script that handles restarts and make it executable. +COPY ./.docker/startup.sh /opt/ +RUN chmod u+x /opt/startup.sh +# Finally, start VNC using our script. +CMD ["/opt/startup.sh"] diff --git a/vnc.sh b/vnc.sh deleted file mode 100644 index 24841692a..000000000 --- a/vnc.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -# Remove VNC lock (if process already killed) -rm /tmp/.X1-lock /tmp/.X11-unix/X1 -# Run VNC server with tail in the foreground -vncserver :1 -randr -geometry 1280x800 -depth 24 && tail -F /root/.vnc/*.log