构建 Docker 镜像

Dockerfile

项目根目录中有一个 Dockerfile 文件,您可以从中构建 Docker 镜像。Dockerfile 中有两种构建方法可供选择。在执行构建命令时,使用 --build-arg 参数来控制镜像版本。--build-arg 参数默认为 yes,这将构建 qlib 镜像的 stable 版本。

1.For the stable version, use pip install pyqlib to build the qlib image.

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/workflow/cli.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. 有关使用 docker 的更多信息,请参见 docker 文档.