Running OpenCV inside Apptainer with GPU support

322 Views Asked by At

I'm trying to run a OpenCV application inside an Apptainer container, in a remote machine, passing the --nv flag for granting GPU support. But then I get this error:

import cv2

ImportError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34` not found (required by /.singularity.d/libs/libGLdispatch.so.0)

If I run the same container without the --nv flag, cv2 imports correctly, but then of course I loose the GPU access. The same container runs correctly on my local machine (with NVIDIA GPU) with --nv flag.

So, I suspect --nv flag specifically in my remote machine. It is probably binding incompatible libraries form the host to the container.

I was hoping someone with Apptainer (singularity) experience could help me figure out how to fix this for my remote machine, or at least point me in the right direction. Thanks!

1

There are 1 best solutions below

0
On

I had the same issue on Ubuntu 22.04.

I found a solution here: https://virtuallab.readthedocs.io/en/latest/install.html (scroll down to "GlibC issues with Ubuntu 22.04+"). A copy of the instructions are below:

  1. Search for a file named nvliblist.conf in your installation. It should be under your Apptainer installation directory. By default this is under /etc/apptainer (I found mine in /opt/apptainer/etc/apptainer)

  2. Make a back-up of this file! cp nvliblist.conf nvliblist.conf.bak

  3. Open the file nvliblist.conf using a text editor.

  4. Delete all of the following lines that appear libGLX.so, libGLX.so.0, libglx.so, libglx.so.0 and libGLdispatch.so. Note, depending on you exact system, the file may not contain all of them.

One caveat with this workaround, however, is that involves messing with configs that apply system wide. As such, it may have unintended side-effects with other software/containers that use Apptainer.

For more info about why this happens: https://github.com/apptainer/apptainer/issues/598#issuecomment-1222698890