我使用以下 Dockerfile 創建了一個 docker 映像
FROM python:latest
WORKDIR /root/my_dir
COPY requirements.txt ./
RUN apt-get update &&\
apt-get upgrade -y &&\
apt-get install -y curl &&\
apt-get install nano &&\
pip3 install -r requirements.txt &&\
然后我將它用作在 docker-compose.yaml 中描述它的服務
version: '2.2'
services:
my_service:
image: my_image
volumes:
- /root/my_dir:/root/my_dir
- /usr/local/cuda-11.0:/usr/local/cuda-11.0
environment:
- LD_LIBRARY_PATH=/usr/local/cuda-11.0/targets/x86_64-linux/lib
command: ["python3"]
stdin_open: true
tty: true
cuda:
image: nvidia/cuda:11.0.3-devel-ubuntu16.04
runtime: nvidia
environment:
- NVIDIA_VISIBLE_DEVICES=all
command: nvidia-smi
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 0
capabilities: [gpu]
driver: nvidia
版本:
Docker version 20.10.7, build f0df350
docker-compose version 1.29.0, build 07737305
docker-ce 5:20.10.7~3-0~ubuntu-xenial
docker-ce-cli 5:20.10.7~3-0~ubuntu-xenial
docker-ce-rootless-extras 5:20.10.7~3-0~ubuntu-xenial
docker-scan-plugin 0.8.0~ubuntu-xenial
nvidia-docker2 2.11.0-1
在我的機器上,我安裝了 cuda 11.0,并使用了 python 3.8 和 tensorflow 2.4.0,如此處所述
https://www.tensorflow.org/install/source#gpu
我運行容器:
docker-compose up
一切似乎都很順利,但是當我附加到容器時,我嘗試用 python 匯入 tensorflow,但它給了我
Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory;
我還嘗試設定與容器外部相同的環境變數
LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64
CUDA_HOME=/usr/local/cuda-11.0
PATH=$PATH:/usr/local/cuda-11.0/bin
但它有任何影響。
我也嘗試了幾個cuda docker鏡像,無事可做。
uj5u.com熱心網友回復:
問題是您在 docker 中創建的兩個不同的服務無法相互通信。
最好的辦法是使用 CUDA 創建一個映像,在其中安裝 python 和 requirememnts.txt。\
這是 docker 檔案的示例:
FROM nvidia/cuda:11.2.0-cudnn8-runtime-ubuntu20.04
WORKDIR /root/my_dir
COPY requirements.txt ./
RUN apt-get update && apt-get upgrade -y &&\
apt-get install -y python3 python3-pip nano
RUN pip3 install --upgrade pip && pip3 install -r requirements.txt
ENV NVIDIA_VISIBLE_DEVICES all
ENV NVIDIA_DRIVER_CAPABILITIES compute,utility
這是碼頭工人撰寫:
version: '2.2'
services:
my_service:
build: .
volumes:
- /root/my_dir:/root/my_dir
command: ["bash"]
stdin_open: true
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
driver: nvidia
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/520889.html
