基於 docker容器搭建機器學習環境

下載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
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章