如何构建图像
章节大纲
-
构建 Docker 镜像
Dockerfile
项目的根目录下有一个
Dockerfile
文件,你可以用它来构建 Docker 镜像。Dockerfile
中有两种构建方法可供选择。执行构建命令时,使用--build-arg
参数来控制镜像版本。--build-arg
参数默认值为yes
,用于构建 Qlib 镜像的 stable 版本。-
对于 stable 版本,使用
pip install pyqlib
来构建 Qlib 镜像。Shelldocker build --build-arg IS_STABLE=yes -t <image name> -f ./Dockerfile . # 或者使用默认值 docker build -t <image name> -f ./Dockerfile .
-
对于 nightly 版本,使用当前源代码来构建 Qlib 镜像。
Shelldocker build --build-arg IS_STABLE=no -t <image name> -f ./Dockerfile .
Qlib 镜像的自动构建
项目的根目录下有一个
build_docker_image.sh
文件,可用于自动构建 Docker 镜像并将其上传到你的 Docker Hub 仓库(可选,需要配置)。Shellsh 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):
如果你想将构建的镜像上传到你的 Docker Hub 仓库,你需要先编辑
build_docker_image.sh
文件,在文件中填写docker_user
,然后执行此文件。如何使用 Qlib 镜像
启动一个新的 Docker 容器
Shelldocker run -it --name <container name> -v <Mounted local directory>:/app <image name>
此时你已进入 Docker 环境,可以运行 Qlib 脚本了。例如:
Shell>>> 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
退出容器
Shell>>> exit
重启容器
Shelldocker start -i -a <container name>
停止容器
Shelldocker stop -i -a <container name>
删除容器
Shelldocker rm <container name>
有关使用 Docker 的更多信息,请参阅 Docker 文档。
-