'Dockerfile not building in Azure
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
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kubatecht |
