In this step, the MONAI Deploy application can now be built into a deployable Docker image using the MONAI Application Packager.
Overview on MONAI Application Packager¶
The MONAI Application Packager (Packager) is a utility for building an application developed with the MONAI Deploy App SDK into a structured MONAI Application Package (MAP).
Basic Usage of MONAI Application Packager¶
monai-deploy package <APP_PATH> --tag <TAG> [--model <MODEL_PATH>] [--log-level <LEVEL>] [-h]
<APP_PATH>: A path to MONAI Deploy Application folder or main code.
--tag, -t <TAG>: A MAP name and optionally a tag in the ‘name:tag’ format.
<APP_PATH> refers to a python code (such as
./my_app.py), only the file would be packaged into the Docker image.
Please specify the application root path which includes
__main__.py file if you want to package the whole application
The file usually would look like below:
# Assuming that the class `App` (that inherits Application) is defined in `app.py`. from app import App if __name__ == "__main__": App(do_run=True)
The following list contains arguments that have default values or are provided through the SDK if these flags are not invoked. However, the user can choose to override these values by invoking these optional flags:
--model, -m <MODEL_PATH>: Path to a model file or a directory containing all models as subdirectories
--requirements, -r <FILE_PATH>: Optional path to requirements.txt containing package dependencies of the application
--log-level, -l <LEVEL>: Set the logging level (
--base <BASE_IMAGE>: Base Docker Image (overrides default
--input-dir, -i <INPUT_DIR>: Directory mounted in container for Application Input (overrides default
--models-dir <MODELS_DIR>: Directory mounted in container for Models Path (overrides default
--output-dir, -o <OUTPUT_DIR>: Directory mounted in container for Application Output (overrides default
--working-dir, -w <WORKDIR>: Directory mounted in container for Application (overrides default
-n: Do not use cache when building image.
--timeout <VALUE>: Timeout (overrides default
0. In seconds.).
--version: Set the version of the Application (overrides default
-h, --help: Show the help message and exit.
Example of using MONAI Application Packager¶
Given an example MONAI Deploy App SDK application with its code residing in a directory
./my_app, packaging this application with the Packager to create a Docker image tagged
my_app:latest would look like this:
$ monai-deploy package ./my_app -t my_app:latest --model ./model.pt Building MONAI Application Package... Successfully built my_app:latest
The MAP image
my_app:latest will be seen in the list of container images on the user’s local machine when the command
docker images is run. The MAP image
my_app:latest will be able to run locally or remotely.
The current implementation (as of
0.1.0) of the Packager ONLY supports CUDA and Pytorch images from
nvcr.ioas base images for the MAP. There are efforts in progress to add support for smaller images from dockerhub.
This release was developed and tested with CUDA 11 and Python 3.8. There are efforts in progress to add support for different versions of the CUDA Toolkit.
See the next page to learn more on how to locally run a MONAI application package image built by the Packager.