0

I'm learning more about Azure, Containers, App Services and the VNet integration (preview).

I can successfully deploy my dotnet core (3.1) API directly to an Azure App Service (Linux flavor) and set up the appropriate VNet integration, which allows the API to access an on-prem 192.168.. address while the API is publicly accessible.

What I would like to do is deploy the code as a Docker image to the Azure Container Registry and then deploy the container image to an App Service and use the same VNet integration.

When I do this the containerized version of the App Service does not reach the same 192.168.. address that the direct-to-app service does.

Azure informs me that more information on this issue can be found here: https://github.com/Azure/app-service-linux-docs/blob/master/app_service_linux_vnet_integration.md

Direct from that link:

Linux App Service VNet Integration Azure Virtual Network (VNet) integration for Linux Web App is currently in Preview. Customers can use the VNet feature for development and integration testing with your web apps. Please do not use the feature for production purposes. Learn about how to configure VNet with your web app.

During Preview you will need to modify your application in order to integrate with VNet. This is a temporary limitation during VNet Preview release, we will remove the limitation before GA. In your application, please use the PORT environment variable as the main web server’s listening port, instead of using a hardcoded port number. The PORT environment variable is automatically set by App Service platform at startup time. For example, for a Node.js Express app, you should have the following code as part of your server.js file. The full example can be found on Github.

app.listen(process.env.PORT);

ASPNETCORE_URLS is the recommended way to configure ASP.NET Core docker image and here is the DockerFile example.

Note: we’re making continuous improvement to this VNet integration Preview feature for Linux web app, we will roll out feature improvements in the next few months.

In short I have to apply a small workaround while VNet is in preview.

The page provides a link to a DockerFile that can apparently be used for dotnet core apps. https://github.com/dotnet/dotnet-docker/blob/7c18c117d9bd2d35e30cdb4a1548ac14b9f0f037/3.0/aspnetcore-runtime/nanoserver-1809/amd64/Dockerfile

If i take a copy of that DockerFile my app no longer compiles with errors around the escape character. If i remove those i then receive other error messages where many of the commands are not known.

My problem is I do not fully understand how to make this work.

What Do i have to include in my apps DockerFile (My verison is below) to make sure that the containerized version of the app is correctly set up to use this workaround?

My current DockerFile (default docker file for the API in Visual Studio). The only thing I changed here was the version of Windows that was being targeted.

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.


FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["AZtoOnPremLDC/AZtoOnPremLDC.csproj", "AZtoOnPremLDC/"]
RUN dotnet restore "AZtoOnPremLDC/AZtoOnPremLDC.csproj"
COPY . .
WORKDIR "/src/AZtoOnPremLDC"
RUN dotnet build "AZtoOnPremLDC.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "AZtoOnPremLDC.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AZtoOnPremLDC.dll"]
Darren Wainwright
  • 30,247
  • 21
  • 76
  • 127

2 Answers2

2

To configure the listening port to ENV PORT during docker build. The ENTRYPOINT command in the Dockerfile looks like this:

ENTRYPOINT "dotnet" "Tutorial.WebApi.dll" --urls="http://0.0.0.0:${PORT:-80}"

For more explanation of the problem with VNet, see my complete answer here

Yorro
  • 11,445
  • 4
  • 37
  • 47
0

According to the message, you do not need to change anything in your Dockerfile to make everything is OK. The environment variable PORT just works in the Azure Web App integrate with Vnet and it's used in your application code when you want to listen to the port, not in the Dockerfile.

What you need to do is that use the suitable base image, create the image with the Dockerfile and then test it until it works fine locally. Then change the listening port with the environment variable PORT in your application with the language you use.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • I have 2 dotnet core code-bases that are identical except one has Docker support. When I deploy the non-docker one to the app service it works with the vnet integration. When I deploy the docker one the app runs but it doesn't use the vnet integration. – Darren Wainwright Feb 13 '20 at 14:09
  • @DarrenWainwright What do you mean non-docker one? You can see the logs to find the reason. As I know, the Linux Web App is a docker itself. So what you do is use the built-in image and publish or use your custom image with the code published in it. – Charles Xu Feb 14 '20 at 01:28
  • I have 2 code bases I'm using to understand how to setup VNet. My non-docker one doesn't contain the items needed to containerize (DockerFile and nuget package), so i deploy the code as-is to an App Service from Visual Studio. The other code base gets containerized into a docker image which Is then deployed to an app service, again via visual studio. Straight code version = Works with VNet when deployed. Containerized version = doesn't work with VNet when deployed. – Darren Wainwright Feb 14 '20 at 14:12
  • @DarrenWainwright If you use the Visual Studio to deploy, maybe you can try to create an image with it and then push the image to ACR, then deploy the web app from the image. – Charles Xu Feb 17 '20 at 02:04