4

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

2 Answers 2

1
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility

You forgot the capability display.

Sign up to request clarification or add additional context in comments.

Comments

0

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
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.