|
| 1 | +.. _docker_image: |
| 2 | + |
| 3 | +================== |
| 4 | +Build Docker Image |
| 5 | +================== |
| 6 | + |
| 7 | +Dockerfile |
| 8 | +========== |
| 9 | + |
| 10 | +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. |
| 11 | +When executing the build command, use the ``--build-arg`` parameter to control the image version. The ``--build-arg`` parameter defaults to ``yes``, which builds the ``stable`` version of the qlib image. |
| 12 | + |
| 13 | +1.For the ``stable`` version, use ``pip install pyqlib`` to build the qlib image. |
| 14 | + |
| 15 | +.. code-block:: bash |
| 16 | +
|
| 17 | + docker build --build-arg IS_STABLE=yes -t <image name> -f ./Dockerfile . |
| 18 | +
|
| 19 | +.. code-block:: bash |
| 20 | +
|
| 21 | + docker build -t <image name> -f ./Dockerfile . |
| 22 | +
|
| 23 | +2. For the ``nightly`` version, use current source code to build the qlib image. |
| 24 | + |
| 25 | +.. code-block:: bash |
| 26 | +
|
| 27 | + docker build --build-arg IS_STABLE=no -t <image name> -f ./Dockerfile . |
| 28 | +
|
| 29 | +Auto build of qlib images |
| 30 | +========================= |
| 31 | + |
| 32 | +1. There is a **build_docker_image.sh** file in the root directory of your project, which can be used to automatically build docker images and upload them to your docker hub repository(Optional, configuration required). |
| 33 | + |
| 34 | +.. code-block:: bash |
| 35 | +
|
| 36 | + sh build_docker_image.sh |
| 37 | + >>> Do you want to build the nightly version of the qlib image? (default is stable) (yes/no): |
| 38 | + >>> Is it uploaded to docker hub? (default is no) (yes/no): |
| 39 | +
|
| 40 | +2. If you want to upload the built image to your docker hub repository, you need to edit your **build_docker_image.sh** file first, fill in ``docker_user`` in the file, and then execute this file. |
| 41 | + |
| 42 | +How to use qlib images |
| 43 | +====================== |
| 44 | +1. Start a new Docker container |
| 45 | + |
| 46 | +.. code-block:: bash |
| 47 | +
|
| 48 | + docker run -it --name <container name> -v <Mounted local directory>:/app <image name> |
| 49 | +
|
| 50 | +2. At this point you are in the docker environment and can run the qlib scripts. An example: |
| 51 | + |
| 52 | +.. code-block:: bash |
| 53 | +
|
| 54 | + >>> python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn |
| 55 | + >>> python qlib/workflow/cli.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml |
| 56 | +
|
| 57 | +3. Exit the container |
| 58 | + |
| 59 | +.. code-block:: bash |
| 60 | +
|
| 61 | + >>> exit |
| 62 | +
|
| 63 | +4. Restart the container |
| 64 | + |
| 65 | +.. code-block:: bash |
| 66 | +
|
| 67 | + docker start -i -a <container name> |
| 68 | +
|
| 69 | +5. Stop the container |
| 70 | + |
| 71 | +.. code-block:: bash |
| 72 | +
|
| 73 | + docker stop -i -a <container name> |
| 74 | +
|
| 75 | +6. Delete the container |
| 76 | + |
| 77 | +.. code-block:: bash |
| 78 | +
|
| 79 | + docker rm <container name> |
| 80 | +
|
| 81 | +7. For more information on using docker see the `docker documentation <https://docs.docker.com/reference/cli/docker/>`_. |
0 commit comments