首页 > 云计算 > > Docker--深度学习环境配置一站式解决方案
我最近有一些nmb想跟大家分享:
1. 在安装某个库的时候,明明是按官方说的一步步来,可是在我电脑上就是各种报错。
2. 直接用pip或者anaconda安装的OpenCV没法调用本地的ffmpeg编解码器,还有一些需要从头编译的库直接利用conda安装也会出现或多或少的问题。
3. 别人放在github的代码我下载到本机后无法直接跑,我只想验证一下他的结果,但是却需要各种依赖库,各种改环境变量,改变我本地的各种设置,最终系统改得连我自己都不认识了,就算跑通了它的代码,要跑另一些又TM不行了。
毕竟不是CS本专业出身,对于操作系统和软件的基础不是很牢固,所以我再折腾了一周之后,终于决定投入docker的怀抱,并且自己封装了一个image,涵盖了目前做研究需要的各种深度学习和软件库:https://hub.docker.com/r/yiminglin/dl-image/ 希望这篇简介可以帮助大家摆脱环境的烦恼:

中文社区给了简洁的概括:
在我看来,就是类似虚拟机的东西,只是不同点是虚拟机的硬件都是靠CPU虚拟出来的,而docker可以调用你的本地硬件进行计算,而且docker的封装更为精简。
Docker中最重要的两个概念就是image和container,我从官网找到了以下解释
Docker objects
When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.
IMAGES
An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the ubuntu image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.
You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.
CONTAINERS
A container is a runnable instance of an image. You can create, run, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state.
By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine.
A container is defined by its image as well as any configuration options you provide to it when you create or run it. When a container stops, any changes to its state that are not stored in persistent storage disappears.
简言之,就像程序和进程的区别一样,程序是一首曲子,和进程则是曲子的一次演奏。当你run一个container后,无论如何折腾当前的container都不会影响到image,当然,如果你想保存你对container的修改,请参考docker的commit命令。
Nvidia-Docker是英伟达官方出品的docker插件,专门用来允许container直接调用本地的英伟达GPU。不过目前只支持linux系统,需要在你的本机安装好CUDA和CUDNN
和github一样,DockerHub是用来分享自己制作的image的平台,我做的image可以在这里找到https://hub.docker.com/r/yiminglin/dl-image/
运行一个container,并且开启交互式的命令行。当你运行这个命令后,就像远程登录了一台服务器一样,进入bash界面。
nvidia-docker run -it yiminglin/dl-image:latest载入home路径到docker的container
需要注意的是一旦你退出某个container,所有你做的东西都不会保存,所以为了保存数据和代码,我们可以把某个目录载入到container中,这样我们在docker中对该目录所做的修改都会保存到本机了。
nvidia-docker run -v /home/yiming/:$(pwd) -it yiminglin/dl-image:latest
使用Jupyter notebook:
Jupyter notebook是做实验保存数据和分析的重要工具,也是我主要用的开发工具,如果你不需要打开命令行,而是直接想使用jupyter,可以用下面的命令:
nvidia-docker run -v /home/yiming/:$(pwd) -it -p 8888:8888 yiminglin/dl-image:latest sh -c "jupyter notebook --allow-root --no-browser --ip 0.0.0.0 /home/yiming"

nvidia-smi




来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31537575/viewspace-3142262/ ,如需转载,请注明出处,否则将追究法律责任。