.. _docker_image: ================== 构建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镜像。 .. code-block:: bash docker build --build-arg IS_STABLE=yes -t -f ./Dockerfile . .. code-block:: bash docker build -t -f ./Dockerfile . 2. 对于 ``nightly`` 版本,使用当前源代码构建qlib镜像。 .. code-block:: bash docker build --build-arg IS_STABLE=no -t -f ./Dockerfile . 自动构建qlib镜像 ========================= 1. 项目根目录下有一个 **build_docker_image.sh** 文件,可用于自动构建docker镜像并上传至您的docker hub仓库(可选功能,需配置)。 .. code-block:: bash 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): 2. 若需将构建的镜像上传至您的docker hub仓库,需先编辑 **build_docker_image.sh** 文件,填写其中的 ``docker_user`` 参数,然后执行该文件。 如何使用qlib镜像 ====================== 1. 启动一个新的Docker容器 .. code-block:: bash docker run -it --name -v :/app 2. 此时您已进入docker环境,可以运行qlib脚本。示例: .. code-block:: bash >>> 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 3. 退出容器 .. code-block:: bash >>> exit 4. 重启容器 .. code-block:: bash docker start -i -a 5. 停止容器 .. code-block:: bash docker stop -i -a 6. 删除容器 .. code-block:: bash docker rm 7. For more information on using docker see the `docker documentation `_.