Repository navigation
Deploy existing docker container from Azure Container Registry to Azure App Service #19543
|
Is it possible to deploy an existing container that was built in a separate CI pipeline and pushed to an existing ACR? When using the Is this by design? Am I thinking about this all wrong? Or am I trying to use .NET Aspire in a way it isn't meant to be used? I want to build the container separately and have aspire orchestrate the azure resource creation and deploy the docker image built in a CI pipeline to the Azure App Service it configures. Below is an example of what I am doing in Aspire. This deploys "successfully" but does not actually deploy the App Service in the resource group that is created. I've omitted the slot configuration code for brevity. var service = builder
.AddContainer("my-container", $"{acrLoginServer}/my-container")
.WithImage($"my-container")
.WithImageTag(imageTag)
.WithHttpEndpoint(targetPort: 8080, name: "http")
.WithHttpHealthCheck(path: "/health", endpointName: "http");
service
.WithExternalHttpEndpoints()
.PublishAsAzureAppServiceWebsite();Edit: I forgot to mention I do have a workaround for this, but it isn't super ideal. The workaround uses the ARG SOURCE_IMAGE
FROM ${SOURCE_IMAGE} |
Replies: 1 comment
|
This is by design in the current App Service integration: it only creates a website for .NET projects and for containers that have a Dockerfile build ( The filter is here: // Support SDK-published .NET programs and containers with Dockerfiles.
if (!resource.SupportsDotnetProgramPublishing() &&
!(resource.IsContainer() && resource.TryGetAnnotationsOfType<DockerfileBuildAnnotation>(out _)))
{
continue;
}Also note that So the pass-through Dockerfile you already use is currently the supported way to get an App Service for an existing image. It is a bit heavier than ideal because Aspire builds and pushes a thin image, but it does give you the App Service and slot: builder.AddAzureAppServiceEnvironment("appservice");
builder.AddDockerfile("my-container", "./passthrough")
.WithBuildArg("SOURCE_IMAGE", $"{acrLoginServer}/my-container:{imageTag}")
.WithHttpEndpoint(targetPort: 8080, name: "http")
.WithHttpHealthCheck("/health")
.WithExternalHttpEndpoints()
.PublishAsAzureAppServiceWebsite((infra, site) => { });I could not find an open issue or PR for prebuilt-image support in the App Service environment, so if you want it natively, opening a feature request for "AddContainer with existing image on Azure App Service" would be the way to track it. |
This is by design in the current App Service integration: it only creates a website for .NET projects and for containers that have a Dockerfile build (
AddDockerfile, orAddProject). A plainAddContainerwith a prebuilt image is skipped when the environment generates its App Service resources, so nothing is created and the deploy "succeeds" without an App Service.The filter is here:
aspire/src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs
Lines 215 to 220 in 9360f2c