SPA docker windows容器的Azure管道构建失败

问题描述 投票:0回答:1

我正在将Asp.net核心与angular和docker windows容器一起使用。这是dockerfile,如下所示:

Dockerfile:

#escape=`
FROM mcr.microsoft.com/powershell:nanoserver-1809 AS downloadnodejs
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip"; `
Expand-Archive nodejs.zip -DestinationPath C:\; `
Rename-Item "C:\node-v10.16.3-win-x64" c:\nodejs

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build
COPY --from=downloadnodejs C:\nodejs\ C:\Windows\system32\
WORKDIR /src
COPY ["DemoAngularWindows.csproj", "./"]
RUN dotnet restore "./DemoAngularWindows.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "DemoAngularWindows.csproj" -c Release -o /app/build

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

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

我运行docker,没有问题。但是现在我将回购推入了天蓝色的开发阶段,并创建了docker构建并将映像推送到容器注册表中。我收到错误消息,内容如下:

Invoke-WebRequest: Access to the path 'C:\nodejs.zip' is denied.
The command 'pwsh -Command $ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue'; Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v10.16.3/node-v10.16.3-win-x64.zip"; Expand-Archive nodejs.zip -DestinationPath C:\; Rename-Item "C:\node-v10.16.3-win-x64" c:\nodejs' returned a non-zero code: 1
##[error]The process 'C:\Program Files\Docker\docker.exe' failed with exit code 1
Finishing: Build and push an image to container registry

enter image description here

azure-pipelines.yml:

trigger:
- master

resources:
- repo: self

variables:
  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '43a885d5-3f2b-417d-9df3-eaac92ed0a20'
  imageRepository: 'demoangularwindows'
  containerRegistry: 'democontainerregistryname.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)/DemoAngularWindows/Dockerfile'
  tag: '$(Build.BuildId)'

  # Agent VM image name
  vmImageName: 'windows-2019'

stages:
- stage: Build
  displayName: Build and push 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)

Ref:https://docs.microsoft.com/en-us/visualstudio/containers/container-tools-react?view=vs-2019#modify-the-dockerfile-windows-containers

请您帮忙解决此问题?

谢谢

angular docker azure-pipelines single-page-application windows-container
1个回答
1
投票

SPA docker Windows容器的Azure管道构建失败

我可以重现此问题:

enter image description here

根据错误消息,此问题被视为权限问题,请尝试创建WORKDIR,然后在该目录中执行SHELL脚本:

FROM mcr.microsoft.com/powershell:nanoserver-1809 AS downloadnodejs
RUN mkdir -p C:\nodejsfolder
WORKDIR C:\nodejsfolder
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]

作为测试,该错误消失了:

enter image description here

希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.