Azure / azure-functions-docker

This repo contains the base Docker images for working with azure functions
MIT License
264 stars 117 forks source link

Linux container created on Windows produces CTP1009: An error occurred while attempting to download the Azure Functions CLI toolset #315

Open chriswill opened 4 years ago

chriswill commented 4 years ago

Using Visual Studio 2019 16.6.3, I create a bare Function app, with an http trigger.

Once this is complete, I right-click the project and choose Add Docker Support. I am running Linux docker containers on a Windows machine.

Pressing F5 to debug run the app, the container appears to build successfully. I can also build it from the command line:

Successfully built c9824aa43e49
Successfully tagged functionapp1:dev

I can also run it from the command line, when using docker run.

However, starting the app seems to fail with this error when run with Visual Studio F5:

error CTP1009: An error occurred while attempting to download the Azure Functions CLI toolset.
1>Done building project "FunctionApp1.csproj" -- FAILED.

I already have the cli tools on my Windows host. How would I get them into the container that I'm building? Wouldn't the image mcr.microsoft.com/azure-functions/dotnet:3.0 that I'm using already have them?

This is my Dockerfile, which is the standard one created by VS:

FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 80

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

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

FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true

When I build this file from the command line using the parameters that VS uses, I get only 5 steps:

D:\src\FunctionApp1>docker build -f "D:\src\FunctionApp1\FunctionApp1\Dockerfile" --force-rm -t functionapp1:dev --target base  --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=FunctionApp1" "D:\src\FunctionApp1"
Sending build context to Docker daemon  16.38kB
Step 1/5 : FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
 ---> 2fe4640c33c3
Step 2/5 : WORKDIR /home/site/wwwroot
 ---> Using cache
 ---> 97a1f23cd03a
Step 3/5 : EXPOSE 80
 ---> Using cache
 ---> eae663d73848
Step 4/5 : LABEL com.microsoft.created-by=visual-studio
 ---> Using cache
 ---> ca4040cad389
Step 5/5 : LABEL com.microsoft.visual-studio.project-name=FunctionApp1
 ---> Using cache
 ---> 5e6809fb5370
Successfully built 5e6809fb5370
Successfully tagged functionapp1:dev

When I build this container from the command line using a more limited series of parameters, I get an expected 16 steps:

D:\src\FunctionApp1>docker build -t functionapp1 -f FunctionApp1/Dockerfile .
Sending build context to Docker daemon  16.38kB
Step 1/16 : FROM mcr.microsoft.com/azure-functions/dotnet:3.0 AS base
 ---> 2fe4640c33c3
Step 2/16 : WORKDIR /home/site/wwwroot
 ---> Using cache
 ---> 97a1f23cd03a
Step 3/16 : EXPOSE 80
 ---> Using cache
 ---> eae663d73848
Step 4/16 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
 ---> 052ed32b57d8
Step 5/16 : WORKDIR /src
 ---> Using cache
 ---> f1bed047a022
Step 6/16 : COPY ["FunctionApp1/FunctionApp1.csproj", "FunctionApp1/"]
 ---> Using cache
 ---> f5a24389cfe0
Step 7/16 : RUN dotnet restore "FunctionApp1/FunctionApp1.csproj"
 ---> Using cache
 ---> 5086f1c4636d
Step 8/16 : COPY . .
 ---> Using cache
 ---> 522eea5a423c
Step 9/16 : WORKDIR "/src/FunctionApp1"
 ---> Using cache
 ---> e1705a301eb1
Step 10/16 : RUN dotnet build "FunctionApp1.csproj" -c Release -o /app/build
 ---> Using cache
 ---> 6a5932b5e4dc
Step 11/16 : FROM build AS publish
 ---> 6a5932b5e4dc
Step 12/16 : RUN dotnet publish "FunctionApp1.csproj" -c Release -o /app/publish
 ---> Using cache
 ---> bbeae3c3ad17
Step 13/16 : FROM base AS final
 ---> eae663d73848
Step 14/16 : WORKDIR /home/site/wwwroot
 ---> Using cache
 ---> 4c288f5d2973
Step 15/16 : COPY --from=publish /app/publish .
 ---> Using cache
 ---> 362aa59d9adc
Step 16/16 : ENV AzureWebJobsScriptRoot=/home/site/wwwroot     AzureFunctionsJobHost__Logging__Console__IsEnabled=true
 ---> Using cache
 ---> b38c1667cb41
Successfully built b38c1667cb41
Successfully tagged functionapp1:latest

It seems that the VS-supplied parameter --target base is the one that is removing the additional steps.

DanielSSilva commented 3 years ago

Hey @chriswill! Did you figure this out? I was doing some tests and I'm able to run thew container successfully, but one of my colleagues can't. From what I've been reading, it might be related to slow network speeds. How did you sort this?

chriswill commented 3 years ago

@DanielSSilva I'm no longer working with containers on this project any longer, so I didn't create or record a solution.

vacuum-in commented 2 years ago

In my case, the resolution was updating the package Microsoft.VisualStudio.Azure.Containers.Tools.Target.

Install-Package Microsoft.VisualStudio.Azure.Containers.Tools.Targets -Version 1.15.1