Windows container image build is failing on this step in dockerfile RUN dotnet publish -c release -o /app

Sunny Mittal 21 Reputation points
2024-09-07T00:26:48.94+00:00

Hello,

I am trying to follow this link to build and create container images in ACR.
https://microsoftlearning.github.io/deploy-and-manage-containers-with-azure-kubernetes-service/Instructions/Labs/Exercise_02_build_linux_windows_container_images.html

Note: I am trying to execute commands from AZ CLI using VS Code terminal on my machines instead of Azure Cloud Shell.

az acr build --registry $env:ACR_NAME --image hellofromdotnet:v1.0 --platform windows --file Dockerfile.windows .

Did managed to build a linux image and push to ACR.

However, when I try to build and push a windows container image it fails on

line:

RUN dotnet publish -c release -o /app

with

error message:

Step 5/11 : RUN dotnet publish -c release -o /app
 ---> Running in dc36f30782ba
  Determining projects to restore...
C:\Program Files\dotnet\sdk\8.0.401\NuGet.targets(174,5): error : Access to the path 'C:\source\dotnetcore-docs-hello-world\obj\dotnetcoresample.csproj.nuget.g.props' is denied. [C:\source\dotnetcore-docs-hello-world\dotnetcoresample.csproj]
The command 'cmd /S /C dotnet publish -c release -o /app' returned a non-zero code: 1
2024/09/07 00:11:55 Container failed during run: build. No retries remaining.
failed to run step ID: build: exit status 1
Run ID: cr9 failed after 2m3s. Error: failed during run, err: exit status 1
Run failed
Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
453 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sander van de Velde | MVP 32,556 Reputation points MVP
    2024-09-07T08:56:15.3033333+00:00

    Hello @Sunny Mittal ,

    welcome to this moderated Azure community forum.

    You mention you are able to build a Linux .Net container, but you are deploying it on a Windows environment.

    Follow this blog post to build and push and pull an Azure Container Instance based on Linux and C#.

    The deployment is done via Azure CLI.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.

    0 comments No comments

  2. Mounika Reddy Anumandla 330 Reputation points Microsoft Vendor
    2024-09-09T06:26:17.9+00:00

    Hi Sunny Mittal,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    The link provided by Sander van de Velde | MVP shows the steps to build and create containers using CLI.

    I have Built a Linux and Windows container images and stored them in Azure Container Registry following the link https://microsoftlearning.github.io/deploy-and-manage-containers-with-azure-kubernetes-service/Instructions/Labs/Exercise_02_build_linux_windows_container_images.html and worked fine.
    User's image

    I was able to deploy windows container through AzCLI using VSCode terminal using the same Dockerfile.User's image

    User's image Additional troubleshooting steps: The error you're encountering a permission issue with accessing or modifying the file dotnetcoresample.csproj.nuget.g.props during the Docker build process. This problem often arises when Docker is not able to properly access or modify files due to file system permission issues. Verify Permissions on the Host System

    1. Check File and Directory Permissions: Ensure that the directory C:\source\dotnetcore-docs-hello-world and its subdirectories have proper read and write permissions.
      • Right-click the directory and select Properties -> Security. Verify that the user or process running Docker has full control or at least read/write access. If you have any further queries, do let us know.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.