Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running headless Chrome with webgl and Nvidia GPU inside a container

I'm trying to run headless chrome inside a docker container with the webgl support and the hardware acceleration. I have a Nvidia graphic card and if I test of the drivers with the command suggested by Nvidia, it is successful

docker run --gpus all nvidia/opengl:base nvidia-smi

This is my dockerfile :

FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu18.04

# Env vars for the nvidia-container-runtime.
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES all

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
        git \
        ca-certificates \
        build-essential \
        g++ \
        libxinerama-dev \
        libxext-dev \
        libxrandr-dev \
        libxi-dev \
        libxcursor-dev \
        libxxf86vm-dev \
        libvulkan-dev && \
    rm -rf /var/lib/apt/lists/*
    


    
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl

RUN  apt-get update \
     && apt-get install -y wget gnupg ca-certificates \
     && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
     && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
     && apt-get update \
     # We install Chrome to get all the OS level dependencies, but Chrome itself
     # is not actually used as it's packaged in the node puppeteer library.
     # Alternatively, we could could include the entire dep list ourselves
     # (https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unix)
     # but that seems too easy to get out of date.
     && apt-get install -y google-chrome-stable \
     && rm -rf /var/lib/apt/lists/* \
     && wget --quiet https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /usr/sbin/wait-for-it.sh \
     && chmod +x /usr/sbin/wait-for-it.sh
     
# Install GTK, pulseaudio and fonts
RUN apt-get update && \
    apt-get -y --no-install-recommends install ca-certificates tzdata \
                       libcanberra-gtk-module libexif12 pulseaudio attr \
                       fonts-dejavu-core fonts-freefont-ttf fonts-guru-extra \
                       fonts-kacst fonts-kacst-one fonts-khmeros-core fonts-lao \
                       fonts-liberation fonts-lklug-sinhala fonts-lohit-guru \
                       fonts-nanum fonts-opensymbol fonts-sil-abyssinica \
                       fonts-sil-padauk fonts-symbola fonts-takao-pgothic \
                       fonts-tibetan-machine fonts-tlwg-garuda-ttf \
                       fonts-tlwg-kinnari-ttf fonts-tlwg-laksaman-ttf \
                       fonts-tlwg-loma-ttf fonts-tlwg-mono-ttf \
                       fonts-tlwg-norasi-ttf fonts-tlwg-purisa-ttf \
                       fonts-tlwg-sawasdee-ttf fonts-tlwg-typewriter-ttf \
                       fonts-tlwg-typist-ttf fonts-tlwg-typo-ttf \
                       fonts-tlwg-umpush-ttf fonts-tlwg-waree-ttf \
                       ttf-bitstream-vera ttf-dejavu-core ttf-ubuntu-font-family \
                       fonts-arphic-ukai fonts-arphic-uming \
                       fonts-ipafont-mincho fonts-ipafont-gothic \
                       fonts-unfonts-core && \
    rm -rf -- /var/lib/apt/lists /tmp/*.deb

however when I run the container with :

docker run -it --gpus all mytest

and I try to capture a screenshot inside the container with:

google-chrome --no-sandbox --headless --screenshot=ss.png  chrome://gpu/

I get the error : Segmentation fault (core dumped)

Any idea ?

like image 644
user2194221 Avatar asked Nov 16 '22 07:11

user2194221


1 Answers

GPU chome headless options are still problematic, especially when You try that in containers. Just update image to current nvidia/opengl:1.2-glvnd-runtime-ubuntu20.04 and You will get output without any memory dump. I had same issues about year ago on some chrome options with vulkan support (now same thing works ok).

like image 99
DMC Avatar answered Nov 24 '22 01:11

DMC