Skip to content

Instantly share code, notes, and snippets.

@neuro-sys
Last active May 17, 2024 06:47
Show Gist options
  • Save neuro-sys/271a61eb3ca0436a79c967572696f2c9 to your computer and use it in GitHub Desktop.
Save neuro-sys/271a61eb3ca0436a79c967572696f2c9 to your computer and use it in GitHub Desktop.
Dockerfile for headless-gl. You also need to run Docker container in "privileged" mode, assign X11 auth volume on the container, and possibly give Xauth access for call from outside.
# Build stage
FROM nvidia/opengl:1.0-glvnd-devel-ubuntu20.04 as builder
# Install node 14.0
RUN apt-get update -y && \
apt-get install -y curl gnupg ca-certificates && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs
# See: https://github.com/stackgl/headless-gl#ubuntudebian
RUN apt-get update -y && \
apt-get install -y build-essential python libxi-dev libglu-dev libglew-dev pkg-config git
WORKDIR /build
COPY package*.json .
COPY my-threejs-app my-threejs-app
RUN npm install --production
COPY tsconfig.json ./
COPY src src
RUN npm run build
# Build headless-gl natively as the prebuilt binary is not compatible
# See https://github.com/stackgl/headless-gl/issues/65#issuecomment-252742795
RUN git clone https://github.com/stackgl/headless-gl.git && \
cd headless-gl && \
git submodule init && \
git submodule update && \
npm install && \
npm run rebuild
# We will later copy headless-gl/build/Release/webgl.node into runtime layer
# Runtime stage, install and copy only what's needed to run
FROM nvidia/opengl:1.0-glvnd-devel-ubuntu20.04
# Install node 14.0
RUN apt-get update -y && \
apt-get install -y curl gnupg ca-certificates && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get install -y nodejs
# See: https://github.com/stackgl/headless-gl#ubuntudebian
RUN apt-get update -y && \
apt-get install -y build-essential python libxi-dev libglu-dev libglew-dev pkg-config git
EXPOSE 80
WORKDIR /app
COPY fonts fonts
COPY --from=builder /build/node_modules node_modules
COPY --from=builder /build/tsconfig.json tsconfig.json
COPY --from=builder /build/dist dist
COPY --from=builder /build/package.json package.json
COPY --from=builder /build/headless-gl/build/Release/webgl.node node_modules/gl/build/Release/webgl.node
ENV DISPLAY :0
CMD [ "node", "dist/src/index.js" ]
@stepancar
Copy link

Sure!
This is a comment with explanation stackgl/headless-gl#116 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment