下载docker镜像

​docker pull ubuntu:18.04​

进入ubuntu系统命令

​docker run -ti ubuntu /bin/bash​

正确退出系统方式


  • 先按,ctrl+p
  • 再按,ctrl+q

这样系统就会在后台继续运行

最好不要使用exit或者ctrl+d来退出,这样整个系统就退出了

退出后再进入ubuntu系统


  • 首先用docker ps -a 查找到该CONTAINER ID对应编号(比如:46432b28493c)
  • 进入该系统docker attach 46432b28493c(此时没反应,ctrl+c就进入到ubuntu系统中去了)

向容器内部复制文件

在容器外部执行:

​docker cp /home/hylink/docker/Anaconda3-5.2.0-Linux-x86_64.sh 46432b28493c:/home​

​docker cp /home/hylink/docker/all_ner.h5.zip 46432b28493c:/home​

​docker cp /home/hylink/docker/all_ner_model_predict.py 46432b28493c:/home​

安装Anaconda

在容器内部执行:

​sh Anaconda3-5.2.0-Linux-x86_64.sh​

更新环境变量

​source ~/.bashrc​

​python -V​

安装相关依赖

​pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​

​pip install paho-mqtt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​

​pip install msgpack-python -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​

​pip install msgpack -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​

​pip install tensorflow==1.14.0 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​

​pip install 'kashgari>=1.0.0,<2.0.0' -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​



问题:

Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.


解决方案:
​pip install -U --ignore-installed wrapt enum34 simplejson netaddr -i http://pypi.douban.com/simple --trusted-host pypi.douban.com​



问题:

FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is


解决方案:
​pip --default-timeout=100 install h5py==2.8.0rc1​



容器内部系统安装软件

​apt-get update​

​apt-get install unzip​

​apt-get install vim​

​apt-get install wget​

解决容器不支持中文的问题


  • 查看容器支持的语言
    ​locale -a​
  • 查看当前使用的字符集
    ​echo $LANG​
  • 安装中文支持
    ​apt-get -y install language-pack-zh-hans​
  • 更改使用的字符集
    ​LANG=zh_CN.utf8​
  • 设置环境变量
    ​vim /etc/profile​​​​export LC_ALL=zh_CN.utf8​
  • 刷新环境变量
    ​source /etc/profile​

中文命名实体识别示例

​root@46432b28493c:/home# python all_ner_model_predict.py​

基于 docker容器搭建机器学习环境_3c