Skip to content

Instantly share code, notes, and snippets.

@bongole
Last active February 9, 2021 09:32
Show Gist options
  • Save bongole/8cb8f33d66cf0f0963c8f29e1d46fc9b to your computer and use it in GitHub Desktop.
Save bongole/8cb8f33d66cf0f0963c8f29e1d46fc9b to your computer and use it in GitHub Desktop.
blender + gpu in docker
# docker run --gpus=all --rm -it -p 3389:3389 --shm-size=256m -u ubuntu --privileged myblender
FROM ubuntu:20.04 as builder
ENV DEBIAN_FRONTEND noninteractive
RUN sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.iij.ad.jp/pub/linux/ubuntu/archive/%g" /etc/apt/sources.list
RUN sed -i "s/# deb-src/deb-src/g" /etc/apt/sources.list
RUN apt-get -y update \
&& apt-get -yy upgrade \
&& apt-get -yy install git libpulse-dev autoconf m4 intltool build-essential dpkg-dev
ARG PULSE_AUDIO_VERSION=13.99.1
WORKDIR /tmp
RUN apt-get source pulseaudio
RUN apt-get build-dep -yy pulseaudio
RUN mkdir -p /tmp/so
WORKDIR /tmp/pulseaudio-$PULSE_AUDIO_VERSION
RUN ./configure \
&& git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git \
&& cd pulseaudio-module-xrdp \
&& ./bootstrap \
&& ./configure PULSE_DIR="/tmp/pulseaudio-$PULSE_AUDIO_VERSION" \
&& make -j \
&& chmod 644 src/.libs/*.so \
&& cp src/.libs/*.so /tmp/so
FROM nvidia/cudagl:11.2.0-runtime-ubuntu20.04
ARG BLENDER_VERSION=2.91
ARG BLENDER_PATCH_VERSION=2.91.2
ARG VIRTUALGL_VERSION=2.6.5
ARG DRIVER_VERSION=460.39
ARG DRIVER_VERSION_PATH=460.39
ARG PULSE_AUDIO_VERSION=13.99.1
ENV DEBIAN_FRONTEND=noninteractive
RUN sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.iij.ad.jp/pub/linux/ubuntu/archive/%g" /etc/apt/sources.list
RUN apt-get -y update \
&& apt-get -yy upgrade \
&& apt-get -y install \
less \
htop \
xserver-xorg-dev \
pkg-config \
sudo \
wget \
curl \
tzdata \
xubuntu-core \
xrdp \
fcitx-mozc \
fonts-ipafont-gothic \
fonts-ipafont-mincho \
vim \
gvfs-bin \
xdg-utils \
pulseaudio \
&& ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime \
&& echo 'Asia/Tokyo' > /etc/timezone \
&& apt-get clean \
&& mkdir -p /var/lib/xrdp-pulseaudio-installer \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/apt/archives/*
COPY --from=builder /tmp/so/module-xrdp-source.so /var/lib/xrdp-pulseaudio-installer
COPY --from=builder /tmp/so/module-xrdp-sink.so /var/lib/xrdp-pulseaudio-installer
COPY --from=builder /tmp/so/module-xrdp-source.so /usr/lib/pulse-$PULSE_AUDIO_VERSION/modules
COPY --from=builder /tmp/so/module-xrdp-sink.so /usr/lib/pulse-$PULSE_AUDIO_VERSION/modules
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
apt-get update && \
apt-get install -y google-chrome-stable && \
rm -rf /var/lib/apt/lists/*
RUN cd /tmp && \
curl -fSsl -O http://us.download.nvidia.com/XFree86/Linux-x86_64/$DRIVER_VERSION_PATH/NVIDIA-Linux-x86_64-$DRIVER_VERSION.run && \
sh NVIDIA-Linux-x86_64-$DRIVER_VERSION.run -x && \
cd NVIDIA-Linux-x86_64-$DRIVER_VERSION && \
./nvidia-installer --silent \
--no-kernel-module \
--install-compat32-libs \
--no-nouveau-check \
--no-nvidia-modprobe \
--no-rpms \
--no-backup \
--no-check-for-alternate-installs \
--no-libglx-indirect \
--no-install-libglvnd && \
mkdir -p /usr/src/nvidia-$DRIVER_VERSION && \
mv LICENSE mkprecompiled kernel /usr/src/nvidia-$DRIVER_VERSION && \
sed '9,${/^\(kernel\|LICENSE\)/!d}' .manifest > /usr/src/nvidia-$DRIVER_VERSION/.manifest && \
rm -rf /tmp/*
RUN cd /tmp \
&& curl -fsSL -O https://jaist.dl.sourceforge.net/project/virtualgl/${VIRTUALGL_VERSION}/virtualgl_${VIRTUALGL_VERSION}_amd64.deb \
&& dpkg -i *.deb \
&& rm -rf /tmp/*
RUN cd /opt \
&& wget https://ftp.nluug.nl/pub/graphics/blender/release/Blender$BLENDER_VERSION/blender-$BLENDER_PATCH_VERSION-linux64.tar.xz \
&& tar xf blender-$BLENDER_PATCH_VERSION-linux64.tar.xz \
&& rm -f *.xz
RUN echo "[Desktop Entry]\n\
Type=Application\n\
Version=1.0\n\
Name=Blender\n\
Icon=/opt/blender-$BLENDER_PATCH_VERSION-linux64/blender.svg\n\
Exec=vglrun /opt/blender-$BLENDER_PATCH_VERSION-linux64/blender\n\
Categories=Graphics;" > /usr/share/applications/blender.desktop \
&& im-config -n fcitx \
&& groupadd -g 1000 ubuntu \
&& useradd -d /home/ubuntu -m -s /bin/bash -u 1000 -g 1000 ubuntu \
&& echo 'ubuntu:ubuntu' | chpasswd \
&& echo "ubuntu ALL=NOPASSWD: ALL" >> /etc/sudoers \
&& echo 'sed -i -e "s/^EnabledIMList.*$/EnabledIMList=fcitx-keyboard-jp:True,mozc:True,fcitx-keyboard-us:False/" /home/ubuntu/.config/fcitx/profile' >> /home/ubuntu/.xsessionrc \
&& chown ubuntu:ubuntu /home/ubuntu/.xsessionrc \
&& echo 'xfce4-session' >> /home/ubuntu/.xsession \
&& sed -i '0,/port=-1/{s/port=-1/port=5901/}' /etc/xrdp/xrdp.ini \
&& mkdir /home/ubuntu/data \
&& chown -R ubuntu:ubuntu /home/ubuntu/ \
&& echo '#!/bin/bash\n\
BUS_ID=$(nvidia-xconfig --query-gpu-info | grep "PCI BusID" | sed -r "s/\s*PCI BusID : PCI:(.*)/\\1/") \n\
sudo nvidia-xconfig -a --allow-empty-initial-configuration --enable-all-gpus --busid $BUS_ID \n\
export GTK_IM_MODULE=fcitx \n\
export QT_IM_MODULE=fcitx \n\
export XMODIFIERS="@im=fcitx" \n\
Xorg :0 & \n\
sleep 5 \n\
export DISPLAY=:0 \n\
startxfce4 & \n\
sudo /etc/init.d/xrdp start \n\
sudo /etc/init.d/dbus start \n\
fcitx -r -d & \n\
/bin/bash' > /start.sh \
&& chmod +x /start.sh \
&& sed -i "s/=console/=anybody/g" /etc/X11/Xwrapper.config \
&& echo 'load-module module-xrdp-sink' >> /etc/pulse/default.pa \
&& echo 'load-module module-xrdp-source' >> /etc/pulse/default.pa \
&& update-alternatives --set x-terminal-emulator /usr/bin/xfce4-terminal.wrapper
ENV PATH /opt/VirtualGL/bin:${PATH}
EXPOSE 3389
CMD /start.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment