Is it possible to use the artifact generated by my Azure Pipeline to build a Docker image? [duplicate]

I have an Azure pipeline that does a dotnet restore, a dotnet build, and a dotnet publish.

Originally, we published the artifact to an Azure App Service.

We would like to switch to Docker. Therefore, we started creating a Dockerfile and a Docker@2 task in our pipeline that builds the image and pushes it to our Azure Container Registry.

In most examples I find, within the Dockerfile, you have to do a dotnet restore, a dotnet build, and a dotnet publish.

But if I’m already doing this in my Azure pipeline, can’t I just copy-paste my artifact from the pipeline to the Docker image?

Similar to this question: Pass artifact to Docker task in Azure DevOps
And this one: Build Docker with artifacts in Azure DevOps Pipeline

I tried to do it this way at the end of my pipeline:

- task: Docker@2
  inputs:
    containerRegistry: '$(containerRegistry)'
    repository: '$(imageRepository)'
    command: 'buildAndPush'
    Dockerfile: '**/Dockerfile'
    buildContext: '$(Build.ArtifactStagingDirectory)'
    tags: |
      $(Build.BuildId)

And, my Dockerfile, which is at the root of my project:

FROM mcr.microsoft.com/dotnet/aspnet:8.0
COPY . App/
WORKDIR /App
EXPOSE 80
EXPOSE 443
ENTRYPOINT ["dotnet", "MyApplication.dll"]

The image is correctly created and published to my Azure Container Registry, but when I try to run the image on Docker Desktop, it tells me that the SDK is not available on the machine. Here is the error :

The command could not be loaded, possibly because:

  • You intended to execute a .NET application:
    The application ‘MyApplication.dll’ does not exist.
  • You intended to execute a .NET SDK command:
    No .NET SDKs were found.

When I’m in a local env, under the /bin/Debug... I have a MyApplication.dll. So I tried to generate the image from the sdk instead:

FROM mcr.microsoft.com/dotnet/sdk:8.0

But now the error is even stranger:

Could not execute because the specified command or file was not found. Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET program, but dotnet-MyApplication.dll does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

I think that I should stick to the aspnet image.

I have two questions then: did I simply not copy (COPY . App/) to the right place in the Dockerfile, or is there something missing in my Dockerfile to import the SDK?

Is it possible to use the artifact generated by my Azure Pipeline to build a Docker image?

5

Below is the sample I attempt on my side, and it can work as expected. You can reference it to try to re-configure your pipeline and ensure all the required artifact files have been copied into the container.

  1. The Dockerfile.
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
EXPOSE 80
EXPOSE 443

COPY . .
RUN dotnet myApp.dll
ENTRYPOINT ["dotnet", "myApp.dll"]
  1. The pipeline YAML.
# azure-pipelines.yml

pool:
  vmImage: ubuntu-latest

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: myApp.sln
    vstsFeed: 'myFeed'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: myApp.sln
    arguments: '--no-restore -c Release'

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: false
    projects: myApp.sln
    arguments: '--no-build -c Release -o "$(Build.ArtifactStagingDirectory)"'
    zipAfterPublish: false
    modifyOutputPath: false

- task: CopyFiles@2
  displayName: 'Copy Dockerfile'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '**/Dockerfile'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'

- task: Docker@2
  displayName: 'Build and Push image'
  inputs:
    containerRegistry: myDockerConnection
    repository: myApp
    Dockerfile: '**/Dockerfile'
    buildContext: '$(Build.ArtifactStagingDirectory)'
    tags: |
     $(Build.BuildId)
     latest

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật