构建Docker镜像

Dockerfile

There is a Dockerfile file in the root directory of the project from which you can build the docker image. There are two build methods in Dockerfile to choose from. 执行构建命令时,使用 --build-arg 参数控制镜像版本。--build-arg 参数默认为 yes,此时会构建 stable 版本的qlib镜像。

1.对于 stable 版本,使用 pip install pyqlib 构建qlib镜像。

docker build --build-arg IS_STABLE=yes -t <image name> -f ./Dockerfile .
docker build -t <image name> -f ./Dockerfile .
  1. 对于 nightly 版本,使用当前源代码构建qlib镜像。

docker build --build-arg IS_STABLE=no -t <image name> -f ./Dockerfile .

自动构建qlib镜像

  1. 项目根目录下有一个 build_docker_image.sh 文件,可用于自动构建docker镜像并上传至您的docker hub仓库(可选功能,需配置)。

sh build_docker_image.sh
>>> Do you want to build the nightly version of the qlib image? (default is stable) (yes/no):
>>> Is it uploaded to docker hub? (default is no) (yes/no):
  1. 若需将构建的镜像上传至您的docker hub仓库,需先编辑 build_docker_image.sh 文件,填写其中的 docker_user 参数,然后执行该文件。

如何使用qlib镜像

  1. 启动一个新的Docker容器

docker run -it --name <container name> -v <Mounted local directory>:/app <image name>
  1. 此时您已进入docker环境,可以运行qlib脚本。示例:

>>> python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn
>>> python qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml
  1. 退出容器

>>> exit
  1. 重启容器

docker start -i -a <container name>
  1. 停止容器

docker stop -i -a <container name>
  1. 删除容器

docker rm <container name>
  1. For more information on using docker see the docker documentation.