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

时间:2020-05-07 05:30:11

标签: angular docker azure-pipelines single-page-application windows-container

我正在将Asp.net core与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)

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

能否请您解决此问题?

谢谢

0 个答案:

没有答案