docker 运行GPU

at 7个月前  ca NVIDIA  pv 391  by touch  

本文dockerfile如下

FROM nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04

# 定义变量
ARG PROGRAM

# 设置时区环境变量为 Asia/Shanghai
ENV TZ=Asia/Shanghai

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone

ENV DEBIAN_FRONTEND noninteractive

# 替换为阿里云软件源
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC

RUN apt-get update
#安装环境
RUN apt-get install python-dev -y && apt-get install wget -y &&  apt-get install chrony -y &&  apt-get install unzip gnupg2 gnupg make gcc g++  curl -y

RUN apt-get clean && rm -rf /var/lib/apt/lists/*
##以下内容根据实际业务修改

docker-compose版本为docker-compose version 1.27.4, build 40524192,docker-compose.yaml内容如下

version: '3.9'
services:
  transcode-service:
    image: transcode-gpu:v1.0.1
    runtime: nvidia
    entrypoint: ["sh", "-c", "/soft/live.sh"]
    #entrypoint: ["sh", "-c", "/soft/offline.sh"]
    #entrypoint: ["sh", "-c", "/soft/all.sh"]
    container_name: transcode-service
    restart: always
    privileged: true
    network_mode: bridge
    ports:
      - "2030-2900:2030-2900"
      - "2000:8000"
    environment:
      - TZ=Asia/Shanghai
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,video,utility


运行nvidia-smi命令如下

root@icbt:/soft/transcode_docker# nvidia-smi
Wed Apr 24 11:11:29 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.223.02   Driver Version: 470.223.02   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
| 36%   43C    P2   112W / 370W |    418MiB / 10009MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A    192088      C   ...ranscoder/live/tranc_live      415MiB |
+-----------------------------------------------------------------------------+

注:必须安装NVIDIA-docker2安装方法请参照https://www.codefarme.com/?id=276

docker运行gpu参考https://qiita.com/nakasuke_/items/ec1b0636416df3c72db3

宿主机NVIDIA下载驱动链接https://www.nvidia.cn/Download/index.aspx?lang=cn

版权声明

本文仅代表作者观点,不代表码农殇立场。
本文系作者授权码农殇发表,未经许可,不得转载。

 

扫一扫在手机阅读、分享本文

已有0条评论
您是本站第12395名访客 今日有0篇新文章 当前在线 16 人