Poznámka:
Přístup k této stránce vyžaduje autorizaci. Můžete se zkusit přihlásit nebo změnit adresáře.
Přístup k této stránce vyžaduje autorizaci. Můžete zkusit změnit adresáře.
Kromě integrovaného interpretu kódu, který poskytují dynamické relace Azure Container Apps, můžete také použít vlastní kontejnery k definování vlastních sandboxů relací.
Uses for custom container sessions
Vlastní kontejnery umožňují vytvářet řešení přizpůsobená vašim potřebám. Umožňují spouštět kód nebo spouštět aplikace v prostředích, která jsou rychlá a dočasné a nabízejí zabezpečené a izolované prostory s hyper-V. Kromě toho je možné je nakonfigurovat s volitelnou izolací sítě. Mezi některé příklady patří:
Interprety kódu: Pokud potřebujete spustit nedůvěryhodný kód v zabezpečených sandboxech jazykem, který není podporovaný v integrovaném interpretu, nebo potřebujete plnou kontrolu nad prostředím interpretu kódu.
Izolované spouštění: Pokud potřebujete spouštět aplikace v nehostinných scénářích s více tenanty, ve kterých má každý tenant nebo uživatel vlastní prostředí v izolovaném prostoru (sandbox). Tato prostředí jsou izolovaná od sebe a od hostitelské aplikace. Mezi příklady patří aplikace, které spouštějí uživatelský kód, kód, který koncovým uživatelům uděluje přístup ke cloudovým prostředím, agentům AI a vývojovým prostředím.
Using custom container sessions
To use custom container sessions, you first create a session pool with a custom container image. Azure Container Apps automaticky spouští kontejnery ve vlastních sandboxech Hyper-V pomocí poskytnuté image. Once the container starts up, it's available to the session pool.
When your application requests a session, an instance is instantly allocated from the pool. The session remains active until it enters an idle state, which is then automatically stopped and destroyed.
Creating a custom container session pool
To create a custom container session pool, you need to provide a container image and pool configuration settings.
Každou relaci vyvoláte nebo komunikujete pomocí požadavků HTTP. Vlastní kontejner musí vystavit server HTTP na portu, který zadáte, aby na tyto požadavky reagoval.
Pokud chcete vytvořit vlastní fond relací kontejnerů pomocí Azure CLI, ujistěte se, že máte nainstalované nejnovější verze Azure CLI a rozšíření Azure Container Apps pomocí následujících příkazů:
az upgrade
az extension add --name containerapp --upgrade --allow-preview true -y
Custom container session pools require a workload profile enabled Azure Container Apps environment. Pokud prostředí nemáte, vytvořte ho az containerapp env create -n <ENVIRONMENT_NAME> -g <RESOURCE_GROUP> --location <LOCATION> --enable-workload-profiles pomocí příkazu.
Use the az containerapp sessionpool create command to create a custom container session pool.
The following example creates a session pool named my-session-pool with a custom container image myregistry.azurecr.io/my-container-image:1.0.
Before you send the request, replace the placeholders between the <> brackets with the appropriate values for your session pool and session identifier.
az containerapp sessionpool create \
--name my-session-pool \
--resource-group <RESOURCE_GROUP> \
--environment <ENVIRONMENT> \
--registry-server myregistry.azurecr.io \
--registry-username <USER_NAME> \
--registry-password <PASSWORD> \
--container-type CustomContainer \
--image myregistry.azurecr.io/my-container-image:1.0 \
--cpu 0.25 --memory 0.5Gi \
--target-port 80 \
--cooldown-period 300 \
--network-status EgressDisabled \
--max-sessions 10 \
--ready-sessions 5 \
--env-vars "key1=value1" "key2=value2" \
--location <LOCATION>
This command creates a session pool with the following settings:
| Parameter | Hodnota | Popis |
|---|---|---|
--name |
my-session-pool |
The name of the session pool. |
--resource-group |
my-resource-group |
The resource group that contains the session pool. |
--environment |
my-environment |
The name or resource ID of the container app's environment. |
--container-type |
CustomContainer |
The container type of the session pool. Must be CustomContainer for custom container sessions. |
--image |
myregistry.azurecr.io/my-container-image:1.0 |
The container image to use for the session pool. |
--registry-server |
myregistry.azurecr.io |
Název hostitele serveru registru kontejneru. |
--registry-username |
my-username |
Uživatelské jméno pro přihlášení k registru kontejneru. |
--registry-password |
my-password |
Heslo pro přihlášení k registru kontejneru. |
--cpu |
0.25 |
Požadovaný počet CPU jader. |
--memory |
0.5Gi |
Požadovaná paměť. |
--target-port |
80 |
The session port used for ingress traffic. |
--cooldown-period |
300 |
The number of seconds that a session can be idle before the session is terminated. The idle period is reset each time the session's API is called. Hodnota musí být mezi 300 a 3600. |
--network-status |
EgressDisabled |
Určuje, jestli je odchozí síťový provoz z relace povolený. Platné hodnoty jsou EgressDisabled (výchozí) a EgressEnabled. |
--max-sessions |
10 |
The maximum number of sessions that can be allocated at the same time. |
--ready-sessions |
5 |
The target number of sessions that are ready in the session pool all the time. Increase this number if sessions are allocated faster than the pool is being replenished. |
--env-vars |
"key1=value1" "key2=value2" |
The environment variables to set in the container. |
--location |
"Supported Location" |
The location of the session pool. |
To check on the status of the session pool, use the az containerapp sessionpool show command:
az containerapp sessionpool show \
--name <SESSION_POOL_NAME> \
--resource-group <RESOURCE_GROUP> \
--query "properties.poolManagementEndpoint" \
--output tsv
To update the session pool, use the az containerapp sessionpool update command.
Důležité
Pokud se relace používá ke spuštění nedůvěryhodného kódu, nezahrnujte informace nebo data, ke kterým nechcete, aby měl nedůvěryhodný kód přístup. Předpokládejme, že kód je škodlivý a má úplný přístup ke kontejneru, včetně jeho proměnných prostředí, tajných kódů a souborů.
Ukládání obrázků do mezipaměti
When a session pool is created or updated, Azure Container Apps caches the container image in the pool. This caching helps speed up the process of creating new sessions.
Jakékoliv změny obrázku se v relacích neprojeví automaticky. To update the image, update the session pool with a new image tag. Pro každou aktualizaci image použijte jedinečnou značku, abyste zajistili, že se nová image natáhne.
Working with sessions
Your application interacts with a session using the session pool's management API.
A pool management endpoint for custom container sessions follows this format: https://<SESSION_POOL>.<ENVIRONMENT_ID>.<REGION>.azurecontainerapps.io.
To retrieve the session pool's management endpoint, use the az containerapp sessionpool show command:
az containerapp sessionpool show \
--name <SESSION_POOL_NAME> \
--resource-group <RESOURCE_GROUP> \
--query "properties.poolManagementEndpoint" \
--output tsv
All requests to the pool management endpoint must include an Authorization header with a bearer token. Informace o ověřování pomocí rozhraní API pro správu fondů najdete v tématu Ověřování.
Each API request must also include the query string parameter identifier with the session ID. Toto jedinečné ID relace umožňuje vaší aplikaci pracovat s konkrétními relacemi. Další informace o identifikátorech relací najdete v tématu Identifikátory relací.
Důležité
The session identifier is sensitive information which requires a secure process as you create and manage its value. To protect this value, your application must ensure each user or tenant only has access to their own sessions. Selhání zabezpečeného přístupu k relacím může mít za následek zneužití nebo neoprávněný přístup k datům uloženým v relacích uživatelů. Další informace najdete v Identifikátorech relací.
Forwarding requests to the session's container:
Anything in the path following the base pool management endpoint is forwarded to the session's container.
Pokud například voláte <POOL_MANAGEMENT_ENDPOINT>/api/uploadfile, požadavek je směrován do kontejneru relace na adrese 0.0.0.0:<TARGET_PORT>/api/uploadfile.
Continuous session interaction:
You can continue making requests to the same session. If there are no requests to the session for longer than the cooldown period, the session is automatically deleted.
Ukázkový požadavek
The following example shows a request to a custom container session by a user ID.
Před odesláním požadavku nahraďte zástupné symboly mezi <> hranatými závorkami hodnotami specifickými pro váš požadavek.
POST https://<SESSION_POOL_NAME>.<ENVIRONMENT_ID>.<REGION>.azurecontainerapps.io/<API_PATH_EXPOSED_BY_CONTAINER>?identifier=<USER_ID>
Authorization: Bearer <TOKEN>
{
"command": "echo 'Hello, world!'"
}
This request is forwarded to the custom container session with the identifier for the user's ID. If the session isn't already running, Azure Container Apps allocates a session from the pool before forwarding the request.
In the example, the session's container receives the request at http://0.0.0.0:<INGRESS_PORT>/<API_PATH_EXPOSED_BY_CONTAINER>.
Použití spravované identity
A managed identity from Microsoft Entra ID allows your custom container session pools and their sessions to access other Microsoft Entra protected resources. Další informace o spravovaných identitách v Microsoft Entra ID najdete v tématu Spravované identity pro prostředky Azure.
You can enable managed identities for your custom container session pools. Podporují se spravované identity přiřazené systémem i spravované uživatelem.
There are two ways to use managed identities with custom container session pools:
Image pull authentication: Use the managed identity to authenticate with the container registry to pull the container image.
Resource access: Use the session pool's managed identity in a session to access other Microsoft Entra protected resources. Vzhledem k tomu, že to má vliv na zabezpečení, je tato funkce ve výchozím nastavení zakázaná.
Důležité
Pokud povolíte přístup k řízené identitě v relaci, může jakýkoli kód nebo jakýkoli program spuštěný v relaci vytvořit tokeny Entra pro řízenou identitu fondu. Since sessions typically run untrusted code, use this feature with caution.
To enable managed identity for a custom container session pool, use Azure Resource Manager.
Logging
Console logs from custom container sessions are available in the Azure Log Analytics workspace associated with the Azure Container Apps environment in a table named AppEnvSessionConsoleLogs_CL.
Fakturace
Custom container sessions are billed based on the resources consumed by the session pool. Další informace najdete v tématu Fakturace Azure Container Apps.