docker 简要使用

ubuntu源的概念
ubuntu不同源的名字
21.04
hirsute
20.10
groovy
18.04
bionic
16.04
xenial
14.04
trusty
focal 指当前系统版本的源
参考 https://wiki.ubuntu.org.cn/源列表

? 为什么要了解源 因为ubuntu20.04还没有自己版本的nvidia-docker, 我们一般使用ubuntu18的

平时我们会在哪些地方使用源? 安装软件, 安装内核

deb http://cn.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
##測試版源
deb http://cn.archive.ubuntu.com/ubuntu/ focal-proposed main restricted universe multiverse
# 源碼
deb-src http://cn.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
##測試版源
deb-src http://cn.archive.ubuntu.com/ubuntu/ focal-proposed main restricted universe multivers

参考地址

官方
https://github.com/nvidia/nvidia-docker/wiki/Installation-(version-2.0)
https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker
https://docs.docker.com/engine/install/ubuntu/
怎么将之前的docker删除干净
https://askubuntu.com/questions/935569/how-to-completely-uninstall-docker
其他issue
In Ubuntu 20.04 can't use nvidia docker
https://askubuntu.com/questions/1249022/in-ubuntu-20-04-cant-use-nvidia-docker
Install nvidia-docker on Ubuntu 20.10.
https://github.com/NVIDIA/nvidia-docker/issues/1407
国内博客
Linux Ubuntu 20.04 docker 安装 GPU 工具箱
https://zhuanlan.zhihu.com/p/418920071
ubuntu+docker使用nvidia显卡运行pytorch
https://zhuanlan.zhihu.com/p/76464450
Docker, 救你于「深度学习环境配置」 的苦海
https://zhuanlan.zhihu.com/p/64493662
如何在 Ubuntu 20.04 上安装和使用 Docker
https://zhuanlan.zhihu.com/p/143156163
国外系列博客 建议把这几个博客看完再看我这个接下来的东西, 博客很短
https://sh-tsang.medium.com/installation-of-docker-3b18d9e70bea
https://sh-tsang.medium.com/docker-tutorial-2-pulling-image-b58326448717
https://sh-tsang.medium.com/docker-tutorial-3-running-images-1dbb76b971af
https://sh-tsang.medium.com/docker-tutorial-4-exporting-container-and-saving-image-c3a7d792cfb6
https://sh-tsang.medium.com/docker-tutorial-5-nvidia-docker-2-0-installation-in-ubuntu-18-04-cb80f17cac65

安装教程 本人电脑Ubuntu 20.04.2 LTS cuda版本10.1
命令(lsb_release -a) (nvcc -V) 蓝色为推荐命令

1 更新安辅助软件
sudo apt update
sudo apt-get install ca-certificates curl gnupg lsb-release
2 Add Docker’s official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archivekeyring.gpg
或者其他网站
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3 Use the following command to set up the stable repository.
echo "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/null
或者其他网站
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs)
stable"
以上会命令会存在两个问题, 1直接获取当前系统对应的源 2网速很慢无法链接
我们必须修改, 1使用自己想要的源版本的docker 2更改下载源为阿里云或者清华
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu/ hirsute stable"
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu/ bionic stable"
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu/ xenial stable" 

4 列出现在可安装的所有docker版本
sudo apt list -a docker-ce
sudo apt list -a docker-ce-cli
apt-cache madison docker-ce

 

我的***项目中, 一般会新建一个shell文件启动docker
比如test.sh
nvidia-docker run -it --net=host --name=myshell --rm \
-v /mnt/data1:/mnt/data1 \
-v /mnt/data3:/mnt/data3 \
-v /mnt/data4:/mnt/data4 \
-v /mnt/data6:/mnt/data6 \
-v /mnt/data7:/mnt/data7 \
-v /mnt/data8:/mnt/data8 \
-w /workspace/***/ \
***name:******版本 \
/bin/bash


--net=host host模式,在这个模式下,docker 不会为容器创建单独的网络 namespace, 而是共享主机的
network namespace, 也就是说: 容器可以直接访问主机上所有的网络信息。
-w
-v 可以将主机上的/mnt/data7地址挂载到容器里/mnt/data7
-d 指定容器后台运行, 一般不加
-i 交互式操作
-t 分配一个伪终端
-p 将容器内部使用的网络端口随机映射到我们使用的主机上
-w: 指定默认工作目录
/bin/bash 进入控制台console默认启动bash 

如果我运行完后,想删除某个正在运行的容器:

sudo docker rm -f myshell

如果容器还在运行,我想重新链接:

sudo docker exec -it myshell /bin/bash

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值