Customize base image for compute session
This section assumes you have knowledge of Docker and Azure Machine Learning environments.
Step-1: Prepare the docker context
Create image_build
folder
In your local environment, create a folder contains following files, the folder structure should look like this:
|--image_build
| |--requirements.txt
| |--Dockerfile
| |--environment.yaml
Define your required packages in requirements.txt
Optional: Add packages in private pypi repository.
Using the following command to download your packages to local: pip wheel <package_name> --index-url=<private pypi> --wheel-dir <local path to save packages>
Open the requirements.txt
file and add your extra packages and specific version in it. For example:
###### Requirements with Version Specifiers ######
langchain == 0.0.149 # Version Matching. Must be version 0.0.149
keyring >= 4.1.1 # Minimum version 4.1.1
coverage != 3.5 # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
<path_to_local_package> # reference to local pip wheel package
For more information about structuring the requirements.txt
file, see Requirements file format in the pip documentation.
Define the Dockerfile
Create a Dockerfile
and add the following content, then save the file:
FROM <Base_image>
COPY ./* ./
RUN pip install -r requirements.txt
Note
This docker image should be built from prompt flow base image that is mcr.microsoft.com/azureml/promptflow/promptflow-runtime:<newest_version>
. If possible use the latest version of the base image.
Step 2: Create custom Azure Machine Learning environment
Define your environment in environment.yaml
In your local compute, you can use the CLI (v2) to create a customized environment based on your docker image.
Note
- Make sure to meet the prerequisites for creating environment.
- Ensure you have connected to your workspace.
az login # if not already authenticated
az account set --subscription <subscription ID>
az configure --defaults workspace=<Azure Machine Learning workspace name> group=<resource group>
Open the environment.yaml
file and add the following content. Replace the <environment_name> placeholder with your desired environment name.
$schema: https://azuremlschemas.azureedge.net/latest/environment.schema.json
name: <environment_name>
build:
path: .
Create an environment
cd image_build
az ml environment create -f environment.yaml --subscription <sub-id> -g <resource-group> -w <workspace>
Note
Building the environment image may take several minutes.
Go to your workspace UI page, then go to the environment page, and locate the custom environment you created.
You can also find the image in environment detail page and use it as base image for compute session of prompt flow. This image will also be used to build environment for flow deployment from UI. Learn more how to specify base image in compute session.
To learn more about environment CLI, see Manage environments.