Docker最基本使用

1 安装:

sudo apt-get -y install docker.io

测试:

sudo docker run hello-world

成功:

Hello from Docker!
This message shows that your installation appears to be working correctly.

2 查看

查看已有镜像:

sudo docker images

查看所有容器

sudo docker ps -a

3 下载镜像

下载CUDA docker

1、宿主机需要安装依赖支持CUDA:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
      && curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
      && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
            sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
            sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list

2、安装

sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker

3、dockerhub这个能有nvcc -V,pytorch等安装的cuda都没有nvcc,只有cudatoolkit.

sudo docker pull nvidia/cuda:11.0.3-devel-ubuntu20.04

4 运行

从镜像中创建一个新的容器:

sudo docker run -it --gpus all --name your_container_name your_image_name:v1

文件夹共享:

sudo docker run -it  -v  /your_dir:/docker_dir --gpus all --name your_container_name your_image_name:v1

启动一个旧的容器:

sudo docker start your_container_name 
sudo docker exec -it your_container_name /bin/bash

文件夹拷贝:

docker  cp /your_dir your_container_name:/docker_dir

关闭容器、删除容器

sudo docker stop your_container_name 
sudo docker rm your_container_name 

5 保存容器为镜像,导出加载

保存为文件

sudo docker commit your_container_name your_image_name:v2

导出、加载

docker save -o your_file_name.tar your_image_name:v1
docker load -i your_file_name.tar	

你可能感兴趣的:(docker,容器,运维)