nvidia-docker镜像制作过程

温馨提示:个人经验,仅供参考

1. 查看已有镜像,在已有镜像基础上建立仓库

$ sudo docker images  # 查看已有镜像
REPOSITORY           TAG                 IMAGE ID            CREATED              SIZE
nvidia/cuda        10.0-cudnn7-devel   bdc0497c2295        5 months ago         3.07GB
ubuntu             latest              3556258649b2        5 months ago         64.2MB

$ sudo nvidia-docker run -it bdc0497c2295   # 运行镜像生成容器
$ sudo nvidia-docker run -it nvidia/cuda:10.0-cudnn7-devel   #运行镜像生成容器(等同于上行命令)
root@2e68413107fb:/#

另开一个终端查看本机存在的所有容器

$ sudo nvidia-docker ps -a
CONTAINER ID        IMAGE                           COMMAND             CREATED             STATUS                     PORTS               NAMES
2e68413107fb        nvidia/cuda:10.0-cudnn7-devel   "/bin/bash"         12 seconds ago      Up 11 seconds                                  hardcore_leakey
c64b1c210171        bdc0497c2295                    "/bin/bash"         3 hours ago         Exited (0) 2 hours ago                         dreamy_haibt

在容器中配置自己需要的环境

首先更新一下apt库,避免找不到安装包,然后安装配置环境
root@2e68413107fb:/# apt-get updata
root@2e68413107fb:/# apt-get upgrade

2. 将安装配置好的仓库commit为新的镜像

$ sudo nvidia-docker commit 2e68413107f new_image:1.0
sha256:2e68413107fb4a27be647b5977bf3a2f33e5a1c1faa089fb7edc363a058bc2ec
$ sudo docker images
REPOSITORY           TAG                 IMAGE ID            CREATED              SIZE
new_image            1.0                 2e68413107f        6 seconds ago        5.73GB
nvidia/cuda        10.0-cudnn7-devel   bdc0497c2295        5 months ago         3.07GB
ubuntu             latest              3556258649b2        5 months ago         64.2MB

3. 将镜像打包成.tar文件

$ sudo nvidia-docker save -o new_image.tar new_image:1.0  #将镜像打包为new_image.tar文件
$ sudo nvidia-docker load < new_image.tar      #将new_image.tar文件load为镜像

未完待续…………

你可能感兴趣的:(Docker,Ubuntu相关问题)