通过docker的pytorch镜像打包自定义环境

30 篇文章 0 订阅

环境:Ubuntu16.04, TITAN V,CUDA9.0

安装Docker

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list |  sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update
sudo apt-get install docker-ce
sudo apt-get install -y nvidia-docker2

设置阿里云镜像加速器

sudo vi /etc/docker/daemon.json

https://cr.console.aliyun.com找到自己的镜像加速器

{
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "registry-mirrors":["https://<your id>.mirror.aliyuncs.com"]
}

配置代理(可选)

/etc/systemd/system/docker.service.d/http-proxy.conf

[Service]
Environment="HTTP_PROXY=http://xx.xx.xx.xx:xx"

容器内部代理似乎只要在一个容器中的~/.bashrc中添加代理各个容器都会生效

export http_proxy="http://xx.xx.xx.xx:xx"

启动docker

sudo systemctl daemon-reload
sudo systemctl restart docker

运行可能的问题

too many open files

可能无影响

拉取pytorch镜像

https://hub.docker.com/查找需要的镜像,例如我需要的是cuda9.0 pytorch4.1

sudo docker pull pytorch/pytorch:0.4.1-cuda9-cudnn7-devel

创建并进入容器

sudo nvidia-docker run --name example --gpus all -ti -v /path/to/some/folder:/workspace --ipc=host 7b329a33d981 /bin/bash

加上--rm参数会在退出后自动删除容器

打包新镜像

在容器内做修改后打包镜像并压缩

sudo docker commit -a "yfraquelle" <container_id> ioid_env:v1
sudo docker save -o yfraquelle_ioid_env_v1.tar ioid_env:v1

加载新镜像

sudo docker load -i yfraquelle_ioid_env_v1.tar

参考链接:

https://www.jianshu.com/p/5b99bc9b0c64

https://zhuanlan.zhihu.com/p/31742065

https://www.pythonf.cn/read/112154

https://discuss.pytorch.org/t/how-to-use-pytorch-docker-image/15929

https://blog.csdn.net/sunmingyang1987/article/details/104555190

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值