当前位置: 首页 > news >正文

Linux(ubuntu) GPU CUDA 构建Docker镜像

一、创建Dockerfile

FROM ubuntu:20.04#非交互式,以快速运行自动化任务或脚本,无需图形界面
ENV DEBIAN_FRONTEND=noninteractive# 安装基础工具
RUN apt-get update && apt-get install -y \curl \wget \git \build-essential \software-properties-common \python3.8 \python3-pip \&& apt-get clean \&& rm -rf /var/lib/apt/lists/*RUN apt-get update && apt-get install -y python3-pip
# 更新 pip 和 setuptools
#RUN python3 -m pip install --upgrade pip setuptools# 添加 NVIDIA CUDA 密钥和仓库
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A4B469963BF863CC \&& echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /" > /etc/apt/sources.list.d/cuda.list# 安装 CUDA 和 cuDNN
RUN apt-get update && apt-get install -y --no-install-recommends \cuda-toolkit-12-4 \libcudnn8 \&& apt-get clean \&& rm -rf /var/lib/apt/lists/*# 设置 Python 3.8 为默认 Python 版本
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1# 安装gpu torch
RUN pip install --timeout=100000 torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 \--index-url https://download.pytorch.org/whl/cu124 \-i https://mirrors.aliyun.com/pypi/simple

注意:cuda-toolkit以及torch相关的版本与cuda的版本都要相匹配,否则会安装失败。有其他需求则可自行更改Dockerfile文件。

二、启动容器并验证

启动容器:docker run -it --name 你的容器名称 --gpus all  你的镜像ID /bin/bash

查看显卡信息:nvidia-smi

验证GPU是否可用:python3 -c "import torch; print(torch.cuda.is_available())"

http://www.lryc.cn/news/541825.html

相关文章:

  • mysql -DQL语句和DCL语句
  • 掌握 ElasticSearch 组合查询:Bool Query 详解与实践
  • C++ 类和对象(友元、内部类、匿名对像)
  • PostgreSQL 常用函数
  • 掌握 ElasticSearch 四种match查询的原理与应用
  • 解决:Conda虚拟环境中未设置CUDA_HOME的问题
  • easyexcel和poi同时存在版本问题,使用easyexcel导出excel设置日期格式
  • HarmonyOS 开发套件 介绍——下篇
  • 关于order by的sql注入实验
  • Transformers快速入门-学习笔记
  • luci界面开发中的MVC架构——LuCI介绍(二)
  • 第1章大型互联网公司的基础架构——1.10 其他NoSQL数据库
  • DeepSeek+Kimi生成高质量PPT
  • web网络安全:跨站脚本攻击(XSS)
  • 【Python爬虫(44)】分布式爬虫:筑牢安全防线,守护数据之旅
  • 微信小程序:多菜单栏设计效果
  • 海康威视摄像头ISUP(原EHOME协议) 摄像头实时预览springboot 版本java实现,并可以在浏览器vue前端播放(附带源码)
  • 蓝桥杯之阶段考核
  • Python爬虫基础重要数据类型
  • 乐享数科:供应链金融—三个不同阶段的融资模式
  • 【AI】openEuler 22.03 LTS SP4安装 docker NVIDIA Container Toolkit
  • 【2025全网首发B站教程】YOLOv12训练数据集构建:标签格式转换-划分-YAML 配置 避坑指南 | 小白也能轻松玩转目标检测!
  • 设计模式教程:中介者模式(Mediator Pattern)
  • 编写dockercompose脚本,管理redis,activemq,mysql5.7
  • 【编程语言】委托与函数指针
  • 基于vue和微信小程序的校园自助打印系统(springboot论文源码调试讲解)
  • 数字后端实现之Innovus中open net原因解析及解决方案
  • MATLAB基础学习相关知识
  • Mac系统下使用Docker快速部署MaxKB:打造本地知识库问答系统
  • RT-Thread+STM32L475VET6——icm20608传感器