-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Simon Zhao <[email protected]>
- Loading branch information
1 parent
06accbf
commit 3d509e0
Showing
3 changed files
with
110 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,115 @@ | ||
Docker Support | ||
============== | ||
The Dockerfile in this directory will build Docker images with all the dependencies and code needed to run example notebooks or unit tests included in this repository. | ||
The Dockerfile in this directory will build Docker images with all | ||
the dependencies and code needed to run example notebooks or unit | ||
tests included in this repository. It is also used by | ||
* [.devcontainer/devcontainer.json](../../.devcontainer/devcontainer.json) | ||
to build | ||
[VS Code Dev Contianers](https://code.visualstudio.com/docs/devcontainers/containers) | ||
that can facilitate the development of Recommenders, | ||
* and [tests/ci/azureml_tests/aml_utils.py](../../tests/ci/azureml_tests/aml_utils.py) | ||
to create the environment in [the testing workflows of Recommenders](../../.github/workflows/). | ||
|
||
Multiple environments are supported by using [multistage builds](https://docs.docker.com/develop/develop-images/multistage-build/). In order to efficiently build the Docker images in this way, [Docker BuildKit](https://docs.docker.com/develop/develop-images/build_enhancements/) is necessary. | ||
The following examples show how to build and run the Docker image for CPU, PySpark, and GPU environments. | ||
Multiple environments are supported by using | ||
[multistage builds](https://docs.docker.com/build/building/multi-stage/). | ||
The following examples show how to build and run the Docker image for | ||
CPU, PySpark, and GPU environments. | ||
|
||
<i>Note:</i> On some platforms, one needs to manually specify the environment variable for `DOCKER_BUILDKIT`to make sure the build runs well. For example, on a Windows machine, this can be done by the powershell command as below, before building the image | ||
``` | ||
$env:DOCKER_BUILDKIT=1 | ||
``` | ||
Once the container is running you can access Jupyter notebooks at | ||
http://localhost:8888. | ||
|
||
<i>Warning:</i> On some platforms using Docker Buildkit interferes with Anaconda environment installation. If you find that the docker build is hanging during Anaconda environment setup stage try building the container without Buildkit enabled. | ||
|
||
Once the container is running you can access Jupyter notebooks at http://localhost:8888. | ||
|
||
Building and Running with Docker | ||
-------------------------------- | ||
|
||
See examples below for the case of conda. If you use venv or virtualenv instead, replace `--build-arg VIRTUAL_ENV=conda` with `--build-arg VIRTUAL_ENV=venv` or `--build-arg VIRTUAL_ENV=virtualenv`, respectively. | ||
<details> | ||
<summary><strong><em>CPU environment</em></strong></summary> | ||
|
||
``` | ||
DOCKER_BUILDKIT=1 docker build -t recommenders:cpu --build-arg ENV=cpu --build-arg VIRTUAL_ENV=conda . | ||
docker run -p 8888:8888 -d recommenders:cpu | ||
``` | ||
* **CPU environment** | ||
|
||
</details> | ||
```bash | ||
docker build -t recommenders:cpu . | ||
docker run -v ../../examples:/root/examples -p 8888:8888 -d recommenders:cpu | ||
``` | ||
|
||
<details> | ||
<summary><strong><em>PySpark environment</em></strong></summary> | ||
|
||
``` | ||
DOCKER_BUILDKIT=1 docker build -t recommenders:pyspark --build-arg ENV=pyspark --build-arg VIRTUAL_ENV=conda . | ||
docker run -p 8888:8888 -d recommenders:pyspark | ||
``` | ||
* **PySpark environment** | ||
|
||
</details> | ||
```bash | ||
docker build -t recommenders:pyspark --build-arg EXTRAS=[spark] . | ||
docker run -v ../../examples:/root/examples -p 8888:8888 -d recommenders:pyspark | ||
``` | ||
|
||
<details> | ||
<summary><strong><em>GPU environment</em></strong></summary> | ||
* **GPU environment** | ||
|
||
``` | ||
DOCKER_BUILDKIT=1 docker build -t recommenders:gpu --build-arg ENV=gpu --build-arg VIRTUAL_ENV=conda . | ||
docker run --runtime=nvidia -p 8888:8888 -d recommenders:gpu | ||
``` | ||
```bash | ||
docker build -t recommenders:gpu --build-arg COMPUTE=gpu . | ||
docker run --runtime=nvidia -v ../../examples:/root/examples -p 8888:8888 -d recommenders:gpu | ||
``` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary><strong><em>GPU + PySpark environment</em></strong></summary> | ||
* **GPU + PySpark environment** | ||
|
||
``` | ||
DOCKER_BUILDKIT=1 docker build -t recommenders:full --build-arg ENV=full --build-arg VIRTUAL_ENV=conda . | ||
docker run --runtime=nvidia -p 8888:8888 -d recommenders:full | ||
``` | ||
```bash | ||
docker build -t recommenders:gpu-pyspark --build-arg COMPUTE=gpu --build-arg EXTRAS=[gpu,spark] . | ||
docker run --runtime=nvidia -v ../../examples:/root/examples -p 8888:8888 -d recommenders:gpu-pyspark | ||
``` | ||
|
||
</details> | ||
|
||
Build Arguments | ||
--------------- | ||
|
||
There are several build arguments which can change how the image is built. Similar to the `ENV` build argument these are specified during the docker build command. | ||
There are several build arguments which can change how the image is | ||
built. Similar to the `ENV` build argument these are specified during | ||
the docker build command. | ||
|
||
Build Arg|Description| | ||
---------|-----------| | ||
ENV|Environment to use, options: cpu, pyspark, gpu, full (defaults to cpu)| | ||
VIRTUAL_ENV|Virtual environment to use; mandatory argument, must be one of "conda", "venv", "virtualenv"| | ||
ANACONDA|Anaconda installation script (defaults to miniconda3 4.6.14)| | ||
`COMPUTE`|Compute to use, options: `cpu`, `gpu` (defaults to `cpu`)| | ||
`EXTRAS`|Extra dependencies to use, options: `dev`, `gpu`, `spark` (defaults to none ("")); For example, `[gpu,spark]`| | ||
`GIT_REF`|Git ref of Recommenders to install, options: `main`, `staging`, etc (defaults to `main`); Empty value means editable installation of current clone| | ||
`JDK_VERSION`|OpenJDK version to use (defaults to `21`)| | ||
`PYTHON_VERSION`|Python version to use (defaults to `3.11`)| | ||
`RECO_DIR`|Path to the copy of Recommenders in the container when `GIT_REF` is empty (defaults to `/root/Recommenders`)| | ||
|
||
Examples: | ||
* Install Python 3.10 and the Recommenders package from the staging branch. | ||
|
||
```bash | ||
docker build -t recommenders:staging --build-arg GIT_REF=staging --build-arg PYTHON_VERSION=3.10 . | ||
``` | ||
|
||
* Install the current local clone of Recommenders and its extra 'dev' dependencies. | ||
|
||
Example: | ||
```bash | ||
# Go to the root directory of Recommenders to copy the local clone into the Docker image | ||
cd ../../ | ||
docker build -t recommenders:dev --build-arg GIT_REF= --build-arg EXTRAS=[dev] -f tools/docker/Dockerfile . | ||
``` | ||
|
||
``` | ||
DOCKER_BUILDKIT=1 docker build -t recommenders:cpu --build-arg ENV=cpu --build-arg VIRTUAL_ENV=conda . | ||
``` | ||
In order to see detailed progress you can provide a flag during the | ||
build command: ```--progress=plain``` | ||
|
||
In order to see detailed progress with BuildKit you can provide a flag during the build command: ```--progress=plain``` | ||
|
||
Running tests with docker | ||
Running tests with Docker | ||
------------------------- | ||
|
||
To run the tests using e.g. the CPU image, do the following: | ||
``` | ||
docker run -it recommenders:cpu bash -c 'pip install pytest; \ | ||
pip install pytest-cov; \ | ||
pip install pytest-mock; \ | ||
apt-get install -y git; \ | ||
git clone https://github.com/recommenders-team/recommenders.git; \ | ||
cd recommenders; \ | ||
pytest tests/unit -m "not spark and not gpu and not notebooks and not experimental"' | ||
``` | ||
* Run the tests using the `recommenders:cpu` image built above. | ||
NOTE: The `recommender:cpu` image only installs the Recommenders | ||
package under [../../recommenders/](../../recommenders/). | ||
|
||
```bash | ||
docker run -it recommenders:cpu bash -c 'pip install pytest; \ | ||
pip install pytest-cov; \ | ||
pip install pytest-mock; \ | ||
apt-get install -y git; \ | ||
git clone https://github.com/recommenders-team/recommenders.git; \ | ||
cd Recommenders; \ | ||
pytest tests/unit -m "not spark and not gpu and not notebooks and not experimental"' | ||
``` | ||
|
||
* Run the tests using the `recommenders:dev` image built above. | ||
NOTE: The `recommenders:dev` image has a full copy of your local | ||
Recommenders repository. | ||
|
||
```bash | ||
docker run -it recommenders:dev bash -c 'cd Recommenders; \ | ||
pytest tests/unit -m "not spark and not gpu and not notebooks and not experimental"' | ||
``` |