Getting Container Error while publishing inside docker file

huangapple go评论57阅读模式
英文:

Getting Container Error while publishing inside docker file

问题

I am building the docker image with .NET7- in Azure Devops with ubuntu-latest agent. all the previous layers untill the publish are successful.but, while publishing the dll, I am getting the below error.

> /root/.nuget/packages/microsoft.net.build.containers/0.4.0/build/Microsoft.NET.Build.Containers.targets(195,5): error CONTAINER1012: The local daemon is not available, but pushing to a local daemon was requested. Please start the daemon and try again.

Here is the docker file

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source
COPY ["src/TestAPI/TestAPI.csproj", "src/TestAPI/"]
RUN dotnet restore "src/TestAPI/TestAPI.csproj"
COPY . .
WORKDIR "/source/src/TestAPI"
RUN dotnet build "TestAPI.csproj" -c Release

FROM build AS publish
WORKDIR /source/src/TestAPI
RUN dotnet publish "TestAPI.csproj" -c Release -o /app/publish

Here is the error from Azure Devops

> MSBuild version 17.6.1+8ffc3fe3d for .NET Determining projects to restore... All projects are up-to-date for restore. TestAPI -> /source/src/TestAPI/bin/Release/net7.0/TestAPI.dll TestAPI -> /app/publish/ Building image 'testwebapi' with tags 1.1.0 on top of base image mcr.microsoft.com:443/dotnet/aspnet:7.0 /root/.nuget/packages/microsoft.net.build.containers/0.4.0/build/Microsoft.NET.Build.Containers.targets(195,5): error CONTAINER1012: The local daemon is not available, but pushing to a local daemon was requested. Please start the daemon and try again. [/source/src/TestAPI/TestAPI.csproj] The command '/bin/sh -c dotnet publish "TestAPI.csproj" -c Release -o /app/publish' returned a non-zero code: 1 ##[error]The command '/bin/sh -c dotnet publish "TestAPI.csproj" -c Release -o /app/publish' returned a non-zero code: 1

Here is the pipeline details

variables: - group: TestAPI_Group - name: imageRepository value: "TestAPIsvc" - name: dockerfilePath value: "Dockerfile" - name: vmImageName value: "ubuntu-latest" - name: BuildConfiguration value: "Release" - name: tag value: "1.0.0"

trigger: - master

stages: - stage: Build displayName: Build stage jobs: - job: Build displayName: Build pool: vmImage: $(vmImageName)

steps: - checkout: self persistCredentials: true

  • task: Docker@2 displayName: 'Build TestAPISvc Image' inputs: repository: '$(imageRepository)' buildContext: '**' command: build Dockerfile: $(dockerfilePath) tags: $(tag)
英文:

I am building the docker image with .NET7- in Azure Devops with ubuntu-latest agent. all the previous layers untill the publish are successful.but, while publishing the dll, I am getting the below error.

> /root/.nuget/packages/microsoft.net.build.containers/0.4.0/build/Microsoft.NET.Build.Containers.targets(195,5):
> error CONTAINER1012: The local daem
on is not available, but pushing to
> a local daemon was requested. Please start the daemon and try again.

Here is the docker file

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source
COPY ["src/TestAPI/TestAPI.csproj", "src/TestAPI/"]
RUN dotnet restore "src/TestAPI/TestAPI.csproj"
COPY . .
WORKDIR "/source/src/TestAPI"
RUN dotnet build "TestAPI.csproj" -c Release

FROM build AS publish
WORKDIR /source/src/TestAPI
RUN dotnet publish "TestAPI.csproj" -c Release -o /app/publish

Here is the error from Azure Devops

> MSBuild version 17.6.1+8ffc3fe3d for .NET Determining projects to
> restore... All projects are up-to-date for restore. TestAPI ->
> /source/src/TestAPI/bin/Release/net7.0/TestAPI.dll TestAPI ->
> /app/publish/ Building image 'testwebapi' with tags 1.1.0 on top of
> base image mcr.microsoft.com:443/dotnet/aspnet:7.0
> /root/.nuget/packages/microsoft.net.build.containers/0.4.0/build/Microsoft.NET.Build.Containers.targets(195,5):
> error CONTAINER1012: The local daemon is not available, but pushing to
> a local daemon was requested. Please start the daemon and try again.
> [/source/src/TestAPI/TestAPI.csproj] The command '/bin/sh -c dotnet
> publish "TestAPI.csproj" -c Release -o /app/publish' returned a
> non-zero code: 1
> ##[error]The command '/bin/sh -c dotnet publish "TestAPI.csproj" -c Release -o /app/publish' returned a non-zero code: 1

Here is the pipeline details

variables:
- group: TestAPI_Group
- name:  imageRepository
  value: "TestAPIsvc"
- name: dockerfilePath
  value: "Dockerfile"
- name: vmImageName
  value: "ubuntu-latest"
- name: BuildConfiguration
  value: "Release"
- name: tag
  value: "1.0.0"


trigger:
- master

stages:
  - stage: Build
    displayName: Build stage
    jobs: 
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)

        steps:
        - checkout: self
          persistCredentials: true

        - task: Docker@2
          displayName: 'Build TestAPISvc Image'
          inputs:
            repository: '$(imageRepository)'
            buildContext: '**'
            command: build
            Dockerfile: $(dockerfilePath)
            tags: $(tag)

答案1

得分: 1

我能够解决这个问题。这个问题是我们正在尝试测试.NET7中引入的新功能,其中我们可以在没有Docker文件的情况下构建Docker镜像,这已经启用,而且我也有一个Docker文件,我在Azure DevOps中用它来构建,某处存在互操作问题。我已经在解决方案级别的Directory.build.props文件中更改了这些设置。

<PropertyGroup>
    <!-- <PublishProfile>DefaultContainer</PublishProfile>
    <ContainerImageTags>1.1.0</ContainerImageTags> -->
</PropertyGroup>

取消了这两个注释后,它开始工作。

英文:

I am able to sove the issue. This issue is we are trying to test the new feature introduced in .NET7 where we can build docker image without docker file, that was enabled and also I have docker file which I used to build in Azure devops, somewhere there is interoperable issue. I have changed this settings in Directory.build.props file at solution level.

 &lt;PropertyGroup&gt;
      &lt;!--&lt;PublishProfile&gt;DefaultContainer&lt;/PublishProfile&gt;
      &lt;ContainerImageTags&gt;1.1.0&lt;/ContainerImageTags&gt;--&gt;
    &lt;/PropertyGroup&gt;

commented these two and it started working.

huangapple
  • 本文由 发表于 2023年5月24日 18:04:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322336.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定