基于Linux,这个是docker file的内容,基于镜像nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04,创建自己的镜像。
# Use NVIDIA CUDA image as the base image
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04
# Every RUN command will create a layer in the image
# Starting with non-interactive package installations
# Replace default apt sources with faster mirrors for China
RUN /bin/bash -c "sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
&& sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
&& apt update && apt upgrade -y"
# Install packages
RUN /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt install tzdata git openssh-server vim zsh make \
sudo net-tools inetutils-ping \
language-pack-zh* -y"
然后运行(注意,xiaoping是指自己的镜像名字,后面有一个空格,然后加 . )
docker build -t xiaoping .
于是就有了自己的镜像(xiaoping)
可以运行以下命令查看
docker images
下边是docker-compose.yml文件内容(利用刚才新建的xiaoping的镜像,建立一个asd的容器,如果要换成别的镜像直接改名字就可以啦。)
另外注意,我这个docker-compose.yml文件挂载了ENVIRONMENTS和SHARE文件夹(会自动创建)。
version: '3.8'
services:
asd:
init: true
container_name: asd
network_mode: "host"
privileged: true
image: xiaoping # Updated to use your custom image
command: tail -f /dev/null
volumes:
- "/tmp/.X11-unix:/tmp/.X11-unix:rw"
- "/dev:/dev:rw"
- "./ENVIRONMENTS:/root/ENVIRONMENTS:rw"
- "./SHARE:/root/SHARE:rw"
working_dir: /root
environment:
- DISPLAY=$DISPLAY
- QT_X11_NO_MITSHM=1
- LC_ALL=zh_CN.UTF-8
- NVIDIA_DRIVER_CAPABILITIES=all
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
最后运行创建容器
docker compose up -d
注意:docker compose 和 docker-compose 是不一样的,直接运行docker compose up -d
命令可以根据你的yml配置文件来进行创建容器。