日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

docker 配置使用宿主机的GPU(ubuntu16.04+cuda10.0+cudnn7)

發(fā)布時間:2023/11/28 生活经验 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 docker 配置使用宿主机的GPU(ubuntu16.04+cuda10.0+cudnn7) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1. 安裝 Docker

  • 卸載舊版本 Docker
sudo apt-get remove docker docker-engine docker.io containerd runc
  • 安裝新版本
sudo apt-get update
sudo apt-get install \ca-certificates \curl \gnupg \lsb-releasecurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgecho \"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

其它安裝方式請參考:
https://docs.docker.com/engine/install/ubuntu/

2. 安裝 nvidia-docker

  • docker 版本 > 19.03 則不需要安裝 nvidia-docker ,只需要安裝 nvidia-container-tookit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \&& curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \&& curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

驗證安裝是否成功

sudo docker run --rm --gpus all nvidia/cuda:10.0-base nvidia-smi

輸出結(jié)果:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.93       Driver Version: 410.93       CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1080    On   | 00000000:01:00.0 Off |                  N/A |
| 37%   22C    P8    14W / 180W |      0MiB /  8119MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 1080    On   | 00000000:82:00.0 Off |                  N/A |
| 37%   20C    P8     9W / 180W |      0MiB /  8119MiB |      0%      Default |
+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

其它測試命令,詳情參考:
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html

#### Test nvidia-smi with the latest official CUDA image
docker run --gpus all nvidia/cuda:10.0-base nvidia-smi# Start a GPU enabled container on two GPUs
docker run --gpus 2 nvidia/cuda:10.0-base nvidia-smi# Starting a GPU enabled container on specific GPUs
docker run --gpus '"device=1,2"' nvidia/cuda:10.0-base nvidia-smi
docker run --gpus '"device=UUID-ABCDEF,1"' nvidia/cuda:10.0-base nvidia-smi# Specifying a capability (graphics, compute, ...) for my container
# Note this is rarely if ever used this way
docker run --gpus all,capabilities=utility nvidia/cuda:10.0-base nvidia-smi
  • docker 版本 < 19.03,則需要安裝 nvidia 官方提供的 nvidia-docker

NVIDIA Docker 地址:
https://github.com/NVIDIA/nvidia-docker

https://www.cnblogs.com/qinlulu/p/14671420.html

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker

3. 下載cuda/nvidia-ubuntu鏡像

docker 鏡像官網(wǎng):https://hub.docker.com/ ,輸入 nvidia/cuda 選擇對應(yīng)的版本。

4. 使用 Dockerfile 構(gòu)建鏡像

直接基于 nvida/cuda ,使用 DockerFile 構(gòu)建一個鏡像

 docker build -t docker_image_name  .

DockerFile 內(nèi)容:

FROM nvidia/cuda:10.0-cudnn7-runtime-ubuntu16.04RUN cat /etc/apt/sources.list && apt-get clean && apt-get -y update --fix-missing
RUN apt-get -y install python3.6 python3-pip && ln -s /usr/bin/python3.6 /usr/bin/python && ln -s /usr/bin/pip3 /usr/bin/pip
RUN apt-get install -y libsm6 libxrender1 libxext-dev
#安裝需要的庫
RUN pip install -i https://mirrors.aliyun.com/pypi/simple/ web.py torch==1.3.1 torchvision==0.4.2 opencv-python scipy flask
RUN apt-get clean && rm -r ~/.cache/pip

其它 Dockerfile

# BASE IMAGE
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu16.04 SHELL ["/bin/bash","-c"]WORKDIR /tmp
# copy安裝文件
COPY Python-3.6.9.tar.xz /tmp
# 設(shè)置 root 密碼
RUN echo 'root:password' | chpasswd \
# 安裝openssh-server 并配置&& apt-get update && apt-get -y install openssh-server \&& sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config \ && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config \&& mkdir /var/run/sshd \
# 安裝python依賴包&& apt-get -y install build-essential python-dev python-setuptools python-pip python-smbus \&& apt-get -y install build-essential libncursesw5-dev libgdbm-dev libc6-dev \&& apt-get -y install zlib1g-dev libsqlite3-dev tk-dev \&& apt-get -y install libssl-dev openssl \&& apt-get -y install libffi-dev \
# 安裝python 3.6.9&& mkdir -p /usr/local/python3.6 \&& tar xvf Python-3.6.9.tar.xz \&& cd Python-3.6.9 \&& ./configure --prefix=/usr/local/python3.6 \&& make altinstall \
# 建立軟鏈接&& ln -snf /usr/local/python3.6/bin/python3.6 /usr/bin/python3 \&& ln -snf /usr/local/python3.6/bin/pip3.6 /usr/bin/pip3\
# 安裝pytorch&& mkdir ~/.pip && echo -e '[global] \nindex-url = https://mirrors.aliyun.com/pypi/simple/' >> ~/.pip/pip.conf \&& pip3 install torch===1.2.0 torchvision===0.4.0 -f https://download.pytorch.org/whl/torch_stable.html \
# 清理copy的安裝文件&& apt-get clean \&& rm -rf /tmp/* /var/tmp/*EXPOSE 22CMD ["/usr/sbin/sshd", "-D"]

參考:
https://www.cnblogs.com/qinlulu/p/14671420.html

https://www.cnblogs.com/shoufu/p/12904832.html

https://blog.csdn.net/weixin_43590796/article/details/114848742#commentBox

https://blog.csdn.net/submarineas/article/details/115558769

總結(jié)

以上是生活随笔為你收集整理的docker 配置使用宿主机的GPU(ubuntu16.04+cuda10.0+cudnn7)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。