最近需要使用 RQAlpha 进行国内的量化分析工作,并对 RQAlpha 进行了容器化处理, 方便使用 docker 和 ks 进行容器化管理
1. 基于 jupyter/minimal-notebook jupyter 的官方镜像,默认使用 python3 2. 使用 Anaconda 的 mini-conda 进行环境管理,可以自由切换 python27 和 python3 运行环境 3. 使用 pip 安装了其他非 conda 管理的包内容
pip install bs4 cx-Oracle docopt future hdfs pyecharts PyMySQL raven typing lxml
4. 使用编译方式安装了 TA-lib, 暂时为 32bit 版本,安装了国内流行的 tushare
pip install tushare TA-lib
5. 将 matplotlib.pyplot 自动导入,同时配合安装了国内流行的 pyechart 6. 安装了 HDFS,cx-Oracle,PyMySQL 等常用的数据连接包
可以在以下位置找到 https://github.com/limccn/rqalpha/tree/master/docker
完整的 Dockerfile 内容
# Copyright (c) Jupyter Development Team.
Distributed under the terms of the Modified BSD License.#
FROM jupyter/minimal-notebook
LABEL maintainer="Jupyter Project "
USER root
libav-tools for matplotlib anim#
RUN apt-get update && \
apt-get install -y --no-install-recommends libav-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
Install TA-lib#
RUN wget https://jaist.dl.sourceforge.net/project/ta-lib/ta-lib/0.4.0/ta-lib-0.4.0-src.tar.gz && \
tar xf ta-lib-0.4.0-src.tar.gz && rm ta-lib-0.4.0-src.tar.gz && \
cd ta-lib && \
./configure --prefix=/usr &&\
make && make install && \
rm -rf /home/$NB_USER/ta-lib
USER $NB_UID
Install Python 3 packages#
Remove pyqt and qt pulled in for matplotlib since we're only ever going to#
use notebook-friendly backends in these images#
RUN conda install --quiet --yes \
'nomkl' \
'ipywidgets=7.1*' \
'pandas=0.19*' \
'numexpr=2.6*' \
'matplotlib=2.0*' \
'scipy=0.19*' \
'seaborn=0.7*' \
'scikit-learn=0.18*' \
'scikit-image=0.12*' \
'sympy=1.0*' \
'cython=0.25*' \
'patsy=0.4*' \
'statsmodels=0.8*' \
'cloudpickle=0.2*' \
'dill=0.2*' \
'numba=0.31*' \
'bokeh=0.12*' \
'sqlalchemy=1.1*' \
'hdf5=1.8.17' \
'h5py=2.6*' \
'vincent=0.4.*' \
'beautifulsoup4=4.5.*' \
'protobuf=3.*' \
'bcolz' \
'xlrd' && \
conda remove --quiet --yes --force qt pyqt && \
conda clean -tipsy && \
# Install RQAlpha
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple rqalpha && \
rm -rf /home/$NB_USER/.rqalpha/bundle/ && \
rqalpha update_bundle && \
# Install RQAlpha libs
pip install bs4 cx-Oracle docopt future hdfs pyecharts PyMySQL raven typing lxml && \
pip install tushare TA-lib && \
rm -rf /home/$NB_USER/.cache/pip/ && \
# Activate ipywidgets extension in the environment that runs the notebook server
jupyter nbextension enable --py widgetsnbextension --sys-prefix && \
# Also activate ipywidgets extension for JupyterLab
jupyter labextension install @jupyter-widgets/jupyterlab-manager@^0.33.1 && \
npm cache clean && \
rm -rf $CONDA_DIR/share/jupyter/lab/staging && \
rm -rf /home/$NB_USER/.cache/yarn && \
rm -rf /home/$NB_USER/.node-gyp && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
Install facets which does not have a pip or conda package at the moment#
RUN cd /tmp && \
git clone https://github.com/PAIR-code/facets.git && \
cd facets && \
jupyter nbextension install facets-dist/ --sys-prefix && \
rm -rf facets && \
fix-permissions $CONDA_DIR && \
fix-permissions /home/$NB_USER
Import matplotlib the first time to build the font cache.#
ENV XDG_CACHE_HOME /home/$NB_USER/.cache/
RUN MPLBACKEND=Agg python -c "import matplotlib.pyplot" && \
fix-permissions /home/$NB_USER
USER $NB_UID