代码之家  ›  专栏  ›  技术社区  ›  Carlo

GPU在正常环境中可见,但在Docker容器中不可见

  •  0
  • Carlo  · 技术社区  · 3 年前

    我正在从一个非常简单的Dockerfile构建一个Docker镜像:

    FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04
    
    ENV DEBIAN_FRONTEND=noninteractive
    
    RUN apt update --fix-missing && \
            apt install python3-pip -y && \
            ln -sf /usr/bin/python3 /usr/bin/python && \
            ln -sf /usr/bin/pip3 /usr/bin/pip
    
    RUN python -m pip install --upgrade pip
    
    RUN pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
    WORKDIR /test
    COPY ./docker_entry_point.sh .
    # entry_point just launching bash
    ENTRYPOINT ["./docker_entry_point.sh"]
    

    我尝试使用以下任一方式运行容器:

    docker run -it --rm --privileged img_name:latest
    docker run -it --rm --gpus all img_name:latest
    

    但在这两种情况下,命令torch.cuda.device_count()都显示0个GPU。

    从容器中,我尝试运行nvidia smi,但得到:

    bash: nvidia-smi: command not found
    

    而nvcc--version返回:

    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2022 NVIDIA Corporation
    Built on Wed_Sep_21_10:33:58_PDT_2022
    Cuda compilation tools, release 11.8, V11.8.89
    Build cuda_11.8.r11.8/compiler.31833905_0
    

    我也试着跑步:

    ls -l /dev/nvidia*
    

    在集装箱里,我得到了:

    ls: cannot access '/dev/nvidia*': No such file or directory
    

    在同一台机器上,我有一个conda环境:

    torch              2.0.0+cu118
    torchaudio         2.0.1+cu118
    torchvision        0.15.1+cu118
    

    从这个环境中,我可以毫无问题地访问GPU。你知道我在这里做错了什么吗?

    0 回复  |  直到 3 年前
        1
  •  1
  •   blue_lama    3 年前

    nvidia-smi: command not found
    建议必须(重新)安装CUDA。