开发语言|Docker部署深度学习

【开发语言|Docker部署深度学习】1.下载Ubuntu

docker pull docker.io/library/ubuntu:18.04

2.通过镜像运行一个容器
[root@localhost ~]# docker run -dit -v /root/lgf:/root/lgf -p 5001:5000 --name=tests docker.io/ubuntu:18.04

-v挂载-p暴露端口 主机地址:容器地址--name取名字
-d后台启动-it以交互方式启动容器
-dit当ENTRYPOINTis bashshdocker run -d ubuntu将立即停止,原因bash是找不到要分配的任何伪终端。必须指定-it以便bashsh可以分配给伪终端。
3.进入容器
docker exec -it tests /bin/bash

安装深度学习环境
1.下载vim(编辑配置文件)
root@a5d1c5b81c15:/# apt-get update root@a5d1c5b81c15:/# apt-get install vim

找到配置文件
vim /etc/apt/sources.list

/etc/apt/sources.list文件的内容清除,然后加入目的软件源的配置。比如拷贝如下内容,便是使用阿里的Ubuntu软件仓库镜像站点,这儿是支持Ubuntu 18的
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

2.安装sudo
root@a5d1c5b81c15:/# apt-get update root@a5d1c5b81c15:/# apt-get install sudo

sudo命令功能:用于普通用户使用管理员权限执行某些操作
3.安装wget
root@a5d1c5b81c15:/# sudo apt-get install wget

4.安装zlib
root@a5d1c5b81c15:/# sudo apt-get install zlib*

5.安装python
root@a5d1c5b81c15:/# sudo wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0rc1.tgz

解压
root@a5d1c5b81c15:/# sudo tar -zxvf Python-3.7.0rc1.tgz

安装gcc和make
sudo apt-get install gcc sudo apt-get install make

进行配置
root@a5d1c5b81c15:/# cd Python-3.7.0rc1 root@a5d1c5b81c15:/Python-3.7.0rc1# ./configure --prefix=/opt/ptyhon3.7

编译及安装
sudo make sudo make install

安装python3.7出现ModuleNotFoundError: No module named ‘_ctypes’解决办法
解决办法:
sudo apt-getupdate
sudo apt-getupgrade
sudo apt-getdist-upgrade
sudo apt-getinstall build-essential python-dev python-setuptools python-pip python-smbus
sudo apt-getinstall build-essential libncursesw5-dev libgdbm-dev libc6-dev
sudo apt-getinstall zlib1g-dev libsqlite3-dev tk-dev
sudo apt-getinstall libssl-dev openssl
sudo apt-getinstall libffi-dev
测试python是否安装成功
python3 -V

安装setuptools
?sudo wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz root@a5d1c5b81c15:/Python-3.7.0rc1# sudo tar -zxvf setuptools-19.6.tar.gz tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6 python3 setup.py build python3 setup.py install?

安装pip
Ubuntu配置pip国内镜像加速安装
root@a5d1c5b81c15:/Python-3.7.0rc1# cd ~/.pip bash: cd: /root/.pip: No such file or directory root@a5d1c5b81c15:/Python-3.7.0rc1# mkdir ~/.pip root@a5d1c5b81c15:/Python-3.7.0rc1# cd ~/.pip root@a5d1c5b81c15:~/.pip# touch pip.conf root@a5d1c5b81c15:~/.pip# sudo gedit ~/.pip/pip.conf sudo: gedit: command not found root@a5d1c5b81c15:~/.pip# sudo apt-get install gedit

下载pip
sudo apt-get install python3-pip

下载深度学习需要的python库
sudo pip install tensorflow==1.9.0 sudo pip install keras==2.3.1

镜像保存 目前已经得到了一个可以快速部署模型的容器,接下来将其做成镜像并保存
在退出容器后将容器保存为镜像
  1. # 命令和git 原理类似
  2. docker commit -m="提交的描述信息" -a="作者" 容器id 目标镜像名:[TAG]
docker commit -a="lgf" -m="deep learning" d798a5946c1f tests:1.0

将该镜像保存为tar文件
docker save tests:1.0 > tests.tar


    推荐阅读