-1

I have a dockerfile that is working on my local machine but is not working on my azure pipelines build.

I've referenced this link here: Docker: COPY failed: file not found in build context (Dockerfile) but was unable to get the docker context for my solution to work properly.

Project File Structure:
AzureProject.sln
|AzureProject
|Classes
||DockerFile
||AzureProject.csproj
.dockerignore
.gitignore

My Docker file is the default file built on creation when you select "include docker" with your .NET 6 project. Again located in: AzureProject/Dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

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

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AzureProject.dll"]

Lastly, my azure-pipelines.yml file looks like

 steps:
 - task: Docker@2
  displayName: buildAndPush
  inputs:
    containerRegistry: AzureCR
    repository: AzureCR-NET6
    Dockerfile: AzureProject/Dockerfile

Edit 1: Folder Structure in VS2022

kubatecht
  • 11
  • 4
  • Can you please format your directory structure with proper indentation instead of pipes? I can't make any sense of what structure you're trying to indicate. – Daniel Mann Mar 22 '22 at 14:40
  • I've added an image of the folder structure in VSCode – kubatecht Mar 22 '22 at 15:07
  • How the project is laid out in visual studio isn't important here. The **actual, on-disk** directory structure is what's important. – Daniel Mann Mar 22 '22 at 17:57
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 23 '22 at 04:18

1 Answers1

0

I was able to discover the solution after looking at the structure on the disk as opposed to in VS thanks to Daniel's suggestion. Found out it was a folder hierarchy issue and that I was being dense by not just looking at it in File Explorer, definitely user error.

To sum up the issue, Dockerfile was building in local but when pushed to a repository and then put through Azure Pipelines the build was failing saying it was unable to find the files for the COPY [AzureProject/AzureProject.csproj, AzureProject/] this was due to the DockerFile being one directory too low, and needed to be moved up a folder so that it had the correct context.

File Structure

kubatecht
  • 11
  • 4