There have been many discussions under this gist about installing docker in Google Colab: https://gist.github.com/mwufi/6718b30761cd109f9aff04c5144eb885
As a possible alternative, Apptainer works on Google Colab.
You can follow the instruction in the document to install it: https://apptainer.org/docs/admin/latest/installation.html#install-ubuntu-packages
It is possible to convert a docker image to .sif file for Apptainer:
!apptainer build hello.sif docker://hello-worldHowever, it is worth noting that Google Colab has some restrictions on root user's capabilities, so you must gain full capabilities in a new user namespace created by unshare -r before running Apptainer as root:
!unshare -r apptainer run hello.sifor just run as a regular user:
# The user in the container will be somebottle
!sudo -u somebottle apptainer run hello.sif
# The user in the container will be root
!sudo -u somebottle apptainer run --fakeroot hello.sifAdditionally, if you want to run a CUDA application inside a container, you need to use flag --nv in the command line, according to https://apptainer.org/docs/user/1.3/gpu.html#requirements
# execute 'nvidia-smi' inside a newly created container
!unshare -r apptainer exec --nv pytorch-gpu.sif nvidia-smiYou may run into a problem like this:
That's because Apptainer depends on ldconfig -p to find shared libraries, but NVIDIA libraries haven't been added to it on Google Colab.
Follow these steps to fix it:
-
Check the
LD_LIBRARY_PATHto find nvidia library path:!unshare -r env | grep LD_ # >> LD_LIBRARY_PATH=/usr/lib64-nvidia
-
Write the nvidia library path into
/etc/ld.so.conf.d/:!echo "/usr/lib64-nvidia" >> /etc/ld.so.conf.d/nvidia.conf
-
Refresh library cache:
!ldconfig
Now you'll be able to find nvidia library files in ldconfig -p, and can execute nvidia-smi command normally:
I hope this helps!
Original post: https://github.com/cat-note/bottleofcat/blob/main/Containerization/GPUApptainerOnGoogleColab.md

