以配置pytorch为例
step 1: 在docker hub上下载镜像
step 2:配置所跑代码需要的环境(采用pip)
pip install -i http://pypi.douban.com/simple/ --trusted-host=pypi.douban.com mmcv opencv-python scipy tb-nightly networkx scikit-image matplotlib future lmdb
step 3:更换apt源
还有一些包我们是需要通过apt-get install来安装的,因此必须要apt-get update 。但是由于apt源的问题,会导致apt-get update 的速度非常慢。因此需要将其换成国内源。
cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份下
rm -r /etc/apt/sources.list #删除原本的
touch /etc/apt/sources.list #创建新的
#因为目前没有vim命令,只能通过echo向文件中添加
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse >> /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse multiverse >> /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse >> /etc/apt/sources.list
echo deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse >> /etc/apt/sources.list
#更新
apt-get update
#安装vim 为了以后方便
apt-get install vim
#axel是用与在终端下载软件的包
apt-get install axel
step 4:下载预训练的模型
axel https://download.pytorch.org/models/vgg19-dcbb9e9d.pth
将其移入/root/.cache/torch/checkpoints/vgg19-dcbb9e9d.pth
mv vgg19-dcbb9e9d.pth /root/.cache/torch/checkpoints/
docker命令
docker images #查看镜像
docker rmi imageID #删除镜像
docker ps #查看正在运行容器
docker ps -a #查看所有容器
docker rm ContainerID #删除容器
docker run -it imageID bash #创建一个容器运行镜像(-it 表示可交互) 可以在里面利用pip或者conda配置环境
docker commit ContainerID newImage #将某容器中的环境制作成新的镜像
docker push newImage #推送镜像