How to use CUDA toolkit and drivers installed in the singularity container and not from the host OS?

I am using base container from

My definition file starts with

Bootstrap: docker
From: nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04

My Host OS has CUDA version 11.0.
I am using the following commands to build my container

singularity build --sandbox mycontainer/ new.def

singularity shell --nv --writable mycontainer/

The –nv flag leads to using drivers from the host OS(cuda 11.0), but I require CUDA 10.0 inside the container.

Also, nvidia-smi doesnt work inside the container, although nvcc --version works.

How to fix this ?

Source: Docker Questions