【开发语言|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当
ENTRYPOINT
is bash
或shdocker run -d ubuntu
将立即停止,原因bash
是找不到要分配的任何伪终端。必须指定-it
以便bash
或sh
可以分配给伪终端。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 multiverse2.安装sudo
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
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
镜像保存 目前已经得到了一个可以快速部署模型的容器,接下来将其做成镜像并保存
在退出容器后将容器保存为镜像
- # 命令和git 原理类似
- 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
推荐阅读
- GoLang底层|GoLang之切片底层系列二(浅显学习)
- 高级Git指南(Git存储,重置,重新设置基准等等)
- Google App Engine Docker容器502错误网关
- Java项目案例|16252行代码!Javaweb开源项目(前后端分离小例子)使用Ajax完成数据交互
- JavaEE|文件操作和IO
- Python|Python(列表浅层快速掌握 —— 创建、访问、增加、删除、修改、统计及计算)
- 西安的朋友们大家好,我在创业做产品,请大家帮帮我
- python|使用Python成功调用大漠插件方法
- JavaSE|Java关键字(四)(abstract)