SPA docker windows 容器的 Azure 管道构建失败
Azure pipelines build failed for SPA docker windows container
我正在使用 Asp.net 核心与 angular 和 docker windows 容器。这是 docker 文件如下:
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 没问题。但现在我已经将 repo 推入 azure devops 并创建了
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
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)
你能帮忙解决这个问题吗?
谢谢
Azure pipelines build failed for SPA docker windows container
我可以在我这边重现这个问题:
根据错误消息,此问题被视为权限问题,请尝试创建一个 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';"]
作为测试,该错误消失了:
希望这对您有所帮助。
我正在使用 Asp.net 核心与 angular 和 docker windows 容器。这是 docker 文件如下:
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 没问题。但现在我已经将 repo 推入 azure devops 并创建了 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
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)
你能帮忙解决这个问题吗?
谢谢
Azure pipelines build failed for SPA docker windows container
我可以在我这边重现这个问题:
根据错误消息,此问题被视为权限问题,请尝试创建一个 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';"]
作为测试,该错误消失了:
希望这对您有所帮助。