Configure a custom container - Azure App Service _ Microsoft Learn
Configure a custom container - Azure App Service _ Microsoft Learn
This article shows you how to configure a custom container to run on Azure App
Service.
This guide provides key concepts and instructions for containerization of Linux apps in
App Service. If are new to Azure App Service, follow the custom container quickstart and
tutorial first. For sidecar containers (preview), see Tutorial: Configure a sidecar container
for custom container in Azure App Service (preview).
Azure CLI
Azure CLI
For <username> and <password>, supply the sign-in credentials for your private
registry account.
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 1/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
1. Enable the system-assigned managed identity for the web app by using the az
webapp identity assign command:
Azure CLI
Replace <app-name> with the name you used in the previous step. The output of
the command (filtered by the --query and --output arguments) is the service
principal ID of the assigned identity.
Azure CLI
Replace <registry-name> with the name of your registry. The output of the
command (filtered by the --query and --output arguments) is the resource ID of
the Azure Container Registry.
Azure CLI
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 2/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
For more information about these permissions, see What is Azure role-based
access control.
4. Configure your app to use the managed identity to pull from Azure Container
Registry.
Azure CLI
Tip
If you are using PowerShell console to run the commands, you need to escape
the strings in the --generic-configurations argument in this and the next
step. For example: --generic-configurations
'{\"acrUseManagedIdentityCreds\": true'
5. (Optional) If your app uses a user-assigned managed identity, make sure the
identity is configured on the web app and then set the
acrUserManagedIdentityID property to specify its client ID:
Azure CLI
Azure CLI
You're all set, and the web app now uses managed identity to pull from Azure Container
Registry.
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 3/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
Azure CLI
using Docker on-premises. Each time the app restarts, App Service does a docker pull ,
but only pulls layers that have changed. If there are no changes, App Service uses
existing layers on the local disk.
If the app changes compute instances for any reason, such as scaling up and down the
pricing tiers, App Service must pull down all layers again. The same is true if you scale
out to add more instances. There are also rare cases where the app instances might
change without a scale operation.
Service app. You can set it via the Cloud Shell . In Bash:
Azure CLI
In PowerShell:
Azure PowerShell
App Service currently allows your container to expose only one port for HTTP requests.
Azure CLI
In PowerShell:
Azure PowerShell
When your app runs, the App Service app settings are injected into the process as
environment variables automatically. You can verify container environment variables
with the URL https://<app-name>.scm.azurewebsites.net/Env .
If your app uses images from a private registry or from Docker Hub, credentials for
accessing the repository are saved in environment variables:
DOCKER_REGISTRY_SERVER_URL , DOCKER_REGISTRY_SERVER_USERNAME and
DOCKER_REGISTRY_SERVER_PASSWORD . Because of security risks, none of these reserved
This method works both for single-container apps or multi-container apps, where the
environment variables are specified in the docker-compose.yml file.
When persistent storage is disabled, then writes to the /home directory aren't persisted
across app restarts or across multiple instances. When persistent storage is enabled, all
writes to the /home directory are persisted and can be accessed by all instances of a
scaled-out app. Additionally, any contents inside the /home directory of the container
are overwritten by any existing files already present on the persistent storage when the
container starts.
The only exception is the /home/LogFiles directory, which is used to store the
container and application logs. This folder always persists upon app restarts if
application logging is enabled with the File System option, independently of the
persistent storage being enabled or disabled. In other words, enabling or disabling the
persistent storage doesn't affect the application logging behavior.
It's recommended to write data to /home or a mounted Azure storage path. Data
written outside these paths isn't persistent during restarts and is saved to platform-
managed host disk space separate from the App Service Plans file storage quota.
By default, persistent storage is disabled on Linux custom containers. To enable it, set
the WEBSITES_ENABLE_APP_SERVICE_STORAGE app setting value to true via the Cloud
Shell . In Bash:
Azure CLI
In PowerShell:
Azure PowerShell
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 6/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
7 Note
Enable SSH
Secure Shell (SSH) is commonly used to execute administrative commands remotely
from a command-line terminal. In order to enable the Azure portal SSH console feature
with custom containers, the following steps are required:
1. Create a standard sshd_config file with the following example contents and place
it on the application project root directory:
Port 2222
ListenAddress 0.0.0.0
LoginGraceTime 180
X11Forwarding yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-
ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
StrictModes yes
SyslogFacility DAEMON
PasswordAuthentication yes
PermitEmptyPasswords no
PermitRootLogin yes
Subsystem sftp internal-sftp
7 Note
This file configures OpenSSH and must include the following items in order to
comply with the Azure portal SSH feature:
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 7/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
cbc,aes256-cbc .
96 .
2. Create an entrypoint script with the name entrypoint.sh (or change any existing
entrypoint file) and add the command to start the SSH service, along with the
application startup command. The following example demonstrates starting a
Python application. Replace the last command according to the project
language/stack:
Debian
Bash
#!/bin/sh
set -e
service ssh start
exec gunicorn -w 4 -b 0.0.0.0:8000 app:app
3. Add to the Dockerfile the following instructions according to the base image
distribution. These instructions copy the new files, install OpenSSH server, set
proper permissions and configure the custom entrypoint, and expose the ports
required by the application and SSH server, respectively:
Debian
Dockerfile
COPY entrypoint.sh ./
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 8/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
ENTRYPOINT [ "./entrypoint.sh" ]
7 Note
The root password must be exactly Docker! as it's used by App Service to let
you access the SSH session with the container. This configuration doesn't
allow external connections to the container. Port 2222 of the container is
accessible only within the bridge network of a private virtual network and isn't
accessible to an attacker on the internet.
4. Rebuild and push the Docker image to the registry, and then test the Web App
SSH feature on Azure portal.
Further troubleshooting information is available at the Azure App Service blog: Enabling
SSH on Linux Web App for Containers
Azure CLI
Replace <app-name> and <resource-group-name> with the names appropriate for your
web app.
Once container logging is turned on, run the following command to see the log stream:
Azure CLI
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 9/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
Azure CLI
YAML
wordpress:
image: <image name:tag>
volumes:
- "${WEBAPP_STORAGE_HOME}/site/wwwroot:/var/www/html"
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 10/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
- "${WEBAPP_STORAGE_HOME}/phpmyadmin:/var/www/phpmyadmin"
- "${WEBAPP_STORAGE_HOME}/LogFiles:/var/log"
Preview limitations
Multi-container is currently in preview. The following App Service platform features
aren't supported:
Authentication / Authorization
Managed Identities
CORS
Virtual network integration isn't supported for Docker Compose scenarios
Docker Compose on Azure App Services currently has a limit of 4,000 characters at
this time.
Supported options
command
entrypoint
environment
image
ports
restart
services
volumes (mapping to Azure Storage is unsupported)
Unsupported options
build (not allowed)
depends_on (ignored)
networks (ignored)
secrets (ignored)
ports other than 80 and 8080 (ignored)
default environment variables like $variable and ${variable} unlike in docker
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 11/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
Syntax Limitations
"version x.x" always needs to be the first YAML statement in the file
ports section must use quoted numbers
image > volume section must be quoted and can't have permissions definitions
volumes section must not have an empty curly brace after the volume name
7 Note
Any other options not explicitly called out are ignored in Public Preview.
robots933456 in logs
You may see the following message in the container logs:
You can safely ignore this message. /robots933456.txt is a dummy URL path that App
Service uses to check if the container is capable of serving requests. A 404 response
simply indicates that the path doesn't exist, but it lets App Service know that the
container is healthy and ready to respond to requests.
Next steps
Tutorial: Migrate custom software to Azure App Service using a custom container
Tutorial: Configure a sidecar container for custom container in Azure App Service
(preview)
Feedback
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 12/13
21/12/2024, 10:33 Configure a custom container - Azure App Service | Microsoft Learn
https://learn.microsoft.com/en-us/azure/app-service/configure-custom-container?tabs=debian&pivots=container-linux 13/13