If I create ASP.NET Core Web App (Razor Pages or Web API) with Docker then I get Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApplication5/WebApplication5.csproj", "WebApplication5/"]
RUN dotnet restore "./WebApplication5/WebApplication5.csproj"
COPY . .
WORKDIR "/src/WebApplication5"
RUN dotnet build "./WebApplication5.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApplication5.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication5.dll"]
The Dockerfile be in the same place where is “csproj”:
Now if I create pipeline (I choose “Deploy to Azure Kubernetes Service”) in Azure DevOps:
I get the pipeline:
trigger:
- master
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: 'b9242279-99b2-45f6-8096-ea3190c4f6ed'
imageRepository: 'xxx'
containerRegistry: 'xxx.azurecr.io'
dockerfilePath: '**/Dockerfile'
tag: '$(Build.BuildId)'
imagePullSecret: 'xxx-auth'
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: Docker@2
displayName: Build and push an image to container registry
inputs:
command: buildAndPush
repository: $(imageRepository)
dockerfile: $(dockerfilePath)
containerRegistry: $(dockerRegistryServiceConnection)
tags: |
$(tag)
- upload: manifests
artifact: manifests
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy
pool:
vmImage: $(vmImageName)
environment: 'xxx.default'
strategy:
runOnce:
deploy:
steps:
- task: KubernetesManifest@0
displayName: Create imagePullSecret
inputs:
action: createSecret
secretName: $(imagePullSecret)
dockerRegistryEndpoint: $(dockerRegistryServiceConnection)
- task: KubernetesManifest@0
displayName: Deploy to Kubernetes cluster
inputs:
action: deploy
manifests: |
$(Pipeline.Workspace)/manifests/deployment.yml
$(Pipeline.Workspace)/manifests/service.yml
imagePullSecrets: |
$(imagePullSecret)
containers: |
$(containerRegistry)/$(imageRepository):$(tag)
As a result when I try to deploy that application using the Azure pipelines I get the error:
##[error]Dockerfile:11
##[error]--------------------
##[error] 9 | ARG BUILD_CONFIGURATION=Release
##[error] 10 | WORKDIR /src
##[error] 11 | >>> COPY ["WebApplication5/WebApplication5.csproj", "WebApplication5/"]
##[error] 12 | RUN dotnet restore "./WebApplication5/WebApplication5.csproj"
##[error] 13 | COPY . .
##[error]--------------------
##[error]ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref c314f485-2f42-4ab2-8fcd-b39be4f6283c::vv9n5bzxz7yeebiyzmmvn6nk7: "/WebApplication5/WebApplication5.csproj": not found
##[error]The process '/usr/bin/docker' failed with exit code 1
BUT if I move Dockerfile above and place it in the same place where is “csproj”:
then I deploy my application successfully but I cannot run my application locally because I have the error:
No Dockerfile could be found. Please make sure you have a Dockerfile called 'Dockerfile' adjacent to the project file.