gmagno
gmagno

Reputation: 2000

How to run OpenCL + OpenGL inside a Docker container?

The aim is to run an OpenCL/OpenGL (interop) app inside a docker container. But I have not been successful yet.

Intro

I have laptop with an NVidia graphics card so I thought leveraging on NVidia Dockerfiles [1,2] would be a good starting point.

The following Dockerfile:

# Dockerfile to run OpenGL app
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES},display
RUN apt-get update && apt-get install -y --no-install-recommends \
        mesa-utils && \
    rm -rf /var/lib/apt/lists/*

works quite well, and I was able to run glxgears.

Running OpenCL on its own container was no big deal either:

# Dockerfile to run OpenCL app
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
        ocl-icd-libopencl1 \
        clinfo && \
    rm -rf /var/lib/apt/lists/*
RUN mkdir -p /etc/OpenCL/vendors && \
    echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

and clinfo successfully shows information about my device.


Attempt

Finally here's my attempt at creating a container with both OpenGL and OpenCL drivers:

# Dockerfile mixing OpenGL and OpenCL
FROM nvidia/opengl:1.0-glvnd-runtime-ubuntu16.04
ENV NVIDIA_DRIVER_CAPABILITIES ${NVIDIA_DRIVER_CAPABILITIES},display
RUN apt-get update && apt-get install -y --no-install-recommends \
        mesa-utils \
        ocl-icd-libopencl1 \
        clinfo && \
    rm -rf /var/lib/apt/lists/*
RUN mkdir -p /etc/OpenCL/vendors && \
    echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

And now, although clinfo still prints OpenCL device information, glxgears on the other hand fails with the following error:

Error: couldn't get an RGB, Double-buffered visual 

Any idea how to make this work? Thanks in advance.


References

Upvotes: 4

Views: 7097

Answers (2)

Merwanski
Merwanski

Reputation: 11

What did work for me is the following

  • STEP 1: added at the end of the Dockerfile the following two lines

      ENV NVIDIA_VISIBLE_DEVICES all
      ENV NVIDIA_DRIVER_CAPABILITIES compute,utility,display
    
  • STEP 2: to run the container

      $ sudo xhost +local:root
      $ docker run --gpus all -it --rm --name container_name \
      -v /tmp/.X11-unix:/tmp/.X11-unix \
      -e DISPLAY=$DISPLAY \
      -e QT_X11_NO_MITSHM=1 \
      --net=host \
      image_name bash
    

Upvotes: 0

kutschkem
kutschkem

Reputation: 8163

ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

You forgot the capability display.

Upvotes: 1

Related Questions