VS Enterprise Containerized a Function App with Azure Function Template

Allan Au 45 Reputation points
2024-05-02T08:09:24.2733333+00:00

Hi,

Created a simple Function App (FuncTest2) in Visual Studio Enterprise 2022 using the Azure Function Template with Docker Support.

The solution is located in C:\Projects\FuncTest2

User's image

Here's the Dockerfile

#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/azure-functions/dotnet:4 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["FuncTest2/FuncTest2.csproj", "FuncTest2/"]
RUN dotnet restore "./FuncTest2/FuncTest2.csproj"
COPY . .
WORKDIR "/src/FuncTest2"
RUN dotnet build "./FuncTest2.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./FuncTest2.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

In Command Prompt, I go to the folder where Dockerfile resides: C:\Projects\FuncTest2\FuncTest2 and execute the Docker command and it would fail:

docker build -t functest2:latest --progress=plain . &> build.log

It fails on the line COPY ["FuncTest2/FuncTest2.csproj", "FuncTest2/"] because it's not able to find FuncTest2.csproj relative to where Dockerfile file is.

However, if I run the debug in Visual Studio it works.

Any ideas?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,678 questions
{count} votes

Accepted answer
  1. LeelaRajeshSayana-MSFT 13,966 Reputation points
    2024-05-03T16:45:04.7733333+00:00

    Hi @Allan Au I'm glad that you were able to resolve your issue and thank you for posting your findings so that others experiencing the same thing can easily reference this! Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to accept the answer .

    Issue:

    Docker build of Azure function app fails because it's not able to find project file relative to where Dockerfile file is.

    Solution:

    Docker build command is being executed from the solution directory and not the project folder.

    If I missed anything please let me know and I'd be happy to add it to my answer, or feel free to comment below with any additional information.

    I hope this helps!

    If you have any other questions, please let me know. Thank you again for your time and patience throughout this issue.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Allan Au 45 Reputation points
    2024-05-02T19:37:19.3733333+00:00

    I don't see a way to delete this question, so I will post what I think is going on.

    Looking at the Output, it seems that docker build is at the solution and not the project folder.

    User's image

    1 person found this answer helpful.
    0 comments No comments