【发布时间】:2019-09-25 05:26:50
【问题描述】:
我的 Dockerfile 有一个基本映像,位于 Azure 容器注册表中。当我在本地运行 Docker 时,图像会构建,但是当我尝试在 Azure Pipelines 中运行它时,它在 Get 上失败:“未授权:需要身份验证”。但是,我在我的 DevOps 项目上创建了一个服务连接(并使其可用于所有管道)并按照the docs 使用它。
这是我的 dockerfile:
FROM myregistry.azurecr.io/bases/netcorenodebase:v1.0 AS base
WORKDIR /app
EXPOSE 80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["MyApp/MyApp.csproj", "MyApp/"]
RUN dotnet restore "MyApp/MyApp.csproj"
COPY . .
WORKDIR "/src/MyApp"
RUN dotnet build "MyApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "MyApp.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "MyApp.dll"]
管道 YAML:
pool:
name: Hosted Ubuntu 1604
variables:
buildConfiguration: 'Release'
steps:
- task: Docker@2
displayName: Login to ACR
inputs:
command: login
containerRegistry: $(dockerServiceConnectionName)
- task: Docker@2
displayName: Build
inputs:
command: build
containerRegistry: $(dockerServiceConnectionName)
repository: myrepo/myimage
tags: |
$(Build.BuildId)
latest
- task: Docker@2
displayName: Push
inputs:
command: push
containerRegistry: $(dockerServiceConnectionName)
repository: myrepo/myimage
tags: |
$(Build.BuildId)
latest
- task: Docker@2
displayName: Logout of ACR
inputs:
command: logout
containerRegistry: $(dockerServiceConnectionName)
dockerServiceConnectionName 变量设置为服务连接的名称,并在登录阶段成功。但似乎上下文没有传递给 Docker 守护进程,因此它无法访问 ACR。我也尝试过 buildAndPush 并且效果相同。我怎样才能让它工作?
【问题讨论】:
标签: docker azure-devops azure-pipelines azure-container-registry