Docker image build fails in Azure DevOps release pipeline

0 votes

I try to run build docker image in Azure DevOps release pipeline however keep ending up this same error:

2020-12-15T03:01:16.5003606Z ##[section]Starting: Build an image
2020-12-15T03:01:16.5014115Z ==============================================================================
2020-12-15T03:01:16.5014678Z Task         : Docker
2020-12-15T03:01:16.5015061Z Description  : Build, tag, push, or run Docker images, or run a Docker command
2020-12-15T03:01:16.5015420Z Version      : 1.177.0
2020-12-15T03:01:16.5015727Z Author       : Microsoft Corporation
2020-12-15T03:01:16.5016278Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/docker
2020-12-15T03:01:16.5016718Z ==============================================================================
2020-12-15T03:01:16.6937336Z [command]/usr/bin/docker build -f /home/vsts/work/r1/a/_API-CI/drop/Dockerfile --label com.azure.dev.image.system.teamfoundationcollectionuri=https://dev.azure.com/yec-addx/ --label com.azure.dev.image.release.releaseid=404 -t app-dms-svc:18773 /home/vsts/work/r1/a/_API-CI-Test/drop
2020-12-15T03:01:17.5040248Z Sending build context to Docker daemon  34.82kB
2020-12-15T03:01:17.5041483Z 
2020-12-15T03:01:17.5786045Z Step 1/30 : FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base
2020-12-15T03:01:17.7515527Z 3.1: Pulling from dotnet/aspnet
2020-12-15T03:01:17.8021916Z 6ec7b7d162b2: Pulling fs layer
2020-12-15T03:01:17.8026791Z f48adbf33222: Pulling fs layer
2020-12-15T03:01:17.8033196Z 0caf687f11cc: Pulling fs layer
2020-12-15T03:01:17.8033852Z 31f7e18202e6: Pulling fs layer
2020-12-15T03:01:17.8034325Z b2b381c9c354: Pulling fs layer
2020-12-15T03:01:17.8034780Z 31f7e18202e6: Waiting
2020-12-15T03:01:17.8035216Z b2b381c9c354: Waiting
2020-12-15T03:01:17.9290990Z 0caf687f11cc: Verifying Checksum
2020-12-15T03:01:17.9292416Z 0caf687f11cc: Download complete
2020-12-15T03:01:18.0089309Z f48adbf33222: Verifying Checksum
2020-12-15T03:01:18.0089790Z f48adbf33222: Download complete
2020-12-15T03:01:18.0704438Z 6ec7b7d162b2: Verifying Checksum
2020-12-15T03:01:18.0704998Z 6ec7b7d162b2: Download complete
2020-12-15T03:01:18.2017214Z b2b381c9c354: Verifying Checksum
2020-12-15T03:01:18.2019195Z b2b381c9c354: Download complete
2020-12-15T03:01:18.3004105Z 31f7e18202e6: Verifying Checksum
2020-12-15T03:01:18.3004679Z 31f7e18202e6: Download complete
2020-12-15T03:01:19.3310801Z 6ec7b7d162b2: Pull complete
2020-12-15T03:01:19.8580822Z f48adbf33222: Pull complete
2020-12-15T03:01:19.9798496Z 0caf687f11cc: Pull complete
2020-12-15T03:01:20.7350092Z 31f7e18202e6: Pull complete
2020-12-15T03:01:21.0029654Z b2b381c9c354: Pull complete
2020-12-15T03:01:21.0092927Z Digest: sha256:f786e94436a4a4f8f86e3d86372d54d6fd39a4085c6416ecaa7096abb72139a0
2020-12-15T03:01:21.0110540Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/aspnet:3.1
2020-12-15T03:01:21.0124473Z  ---> 96df76fbb586
2020-12-15T03:01:21.0124866Z Step 2/30 : WORKDIR /app
2020-12-15T03:01:25.0615009Z  ---> Running in 075aad14591b
2020-12-15T03:01:26.0301515Z Removing intermediate container 075aad14591b
2020-12-15T03:01:26.0302971Z  ---> 97785a46279a
2020-12-15T03:01:26.0303398Z Step 3/30 : EXPOSE 80
2020-12-15T03:01:26.0741271Z  ---> Running in d293786a3b5f
2020-12-15T03:01:27.0313315Z Removing intermediate container d293786a3b5f
2020-12-15T03:01:27.0314388Z  ---> 073ddf35b4bb
2020-12-15T03:01:27.0316530Z Step 4/30 : ENV ASPNETCORE_ENVIRONMENT #{environment-profile}#
2020-12-15T03:01:27.0794751Z  ---> Running in 90bdc7a5eb25
2020-12-15T03:01:28.0349863Z Removing intermediate container 90bdc7a5eb25
2020-12-15T03:01:28.0350869Z  ---> b8924a7ede92
2020-12-15T03:01:28.0351186Z Step 5/30 : FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
2020-12-15T03:01:28.2223262Z 3.1: Pulling from dotnet/sdk
2020-12-15T03:01:28.2710847Z 6c33745f49b4: Pulling fs layer
2020-12-15T03:01:28.2716652Z c87cd3c61e27: Pulling fs layer
2020-12-15T03:01:28.2723430Z 05a3c799ec37: Pulling fs layer
2020-12-15T03:01:28.2723954Z a61c38f966ac: Pulling fs layer
2020-12-15T03:01:28.2724478Z 9bec9ebf31b8: Pulling fs layer
2020-12-15T03:01:28.2724953Z 14e4ab7258ae: Pulling fs layer
2020-12-15T03:01:28.2725411Z 7c3331157193: Pulling fs layer
2020-12-15T03:01:28.2726244Z 9bec9ebf31b8: Waiting
2020-12-15T03:01:28.2726679Z 14e4ab7258ae: Waiting
2020-12-15T03:01:28.2727087Z 7c3331157193: Waiting
2020-12-15T03:01:28.2727515Z a61c38f966ac: Waiting
2020-12-15T03:01:28.4072812Z c87cd3c61e27: Verifying Checksum
2020-12-15T03:01:28.4073267Z c87cd3c61e27: Download complete
2020-12-15T03:01:28.8336537Z 05a3c799ec37: Verifying Checksum
2020-12-15T03:01:28.8338032Z 05a3c799ec37: Download complete
2020-12-15T03:01:29.2910749Z 9bec9ebf31b8: Verifying Checksum
2020-12-15T03:01:29.2911197Z 9bec9ebf31b8: Download complete
2020-12-15T03:01:29.9255263Z 6c33745f49b4: Verifying Checksum
2020-12-15T03:01:29.9256022Z 6c33745f49b4: Download complete
2020-12-15T03:01:30.3046948Z 14e4ab7258ae: Verifying Checksum
2020-12-15T03:01:30.3047610Z 14e4ab7258ae: Download complete
2020-12-15T03:01:30.5555099Z 7c3331157193: Verifying Checksum
2020-12-15T03:01:30.5555466Z 7c3331157193: Download complete
2020-12-15T03:01:31.6943319Z a61c38f966ac: Verifying Checksum
2020-12-15T03:01:31.6943703Z a61c38f966ac: Download complete
2020-12-15T03:01:31.9483489Z 6c33745f49b4: Pull complete
2020-12-15T03:01:32.2423105Z c87cd3c61e27: Pull complete
2020-12-15T03:01:32.5291526Z 05a3c799ec37: Pull complete
2020-12-15T03:01:34.3929707Z a61c38f966ac: Pull complete
2020-12-15T03:01:34.7382829Z 9bec9ebf31b8: Pull complete
2020-12-15T03:01:38.5400926Z 14e4ab7258ae: Pull complete
2020-12-15T03:01:39.1410653Z 7c3331157193: Pull complete
2020-12-15T03:01:39.6864065Z Digest: sha256:6cced85f21def1bae815ce617f9cb55ccb3377690e23055b041adec55a850f2d
2020-12-15T03:01:39.7391308Z Status: Downloaded newer image for mcr.microsoft.com/dotnet/sdk:3.1
2020-12-15T03:01:39.7406175Z  ---> 0b14e54e08b0
2020-12-15T03:01:39.7406506Z Step 6/30 : WORKDIR /src
2020-12-15T03:01:47.4881321Z  ---> Running in 9ded1512b378
2020-12-15T03:01:48.2034673Z Removing intermediate container 9ded1512b378
2020-12-15T03:01:48.2037250Z  ---> 5129c58ae836
2020-12-15T03:01:48.2037635Z Step 7/30 : COPY ["Main/Api/Api.csproj", "Main/Api/"]
2020-12-15T03:01:49.0387358Z  ---> 915df76dc86d
2020-12-15T03:01:49.0388090Z Step 8/30 : COPY ["Main/Domain/Domain.csproj", "Main/Domain/"]
2020-12-15T03:01:50.0426823Z  ---> cc78e935e069
2020-12-15T03:01:50.0427278Z Step 9/30 : COPY ["Infra/Infra.csproj", "Infra/"]
2020-12-15T03:01:51.0482619Z  ---> a7dcd457b2d1
2020-12-15T03:01:51.0483103Z Step 10/30 : COPY ["DataModel/DataModel.csproj", "DataModel/"]
2020-12-15T03:01:52.0507263Z  ---> 57c0b9310f4a
2020-12-15T03:01:52.0507694Z Step 11/30 : COPY ["Infra.Api/Infra.Api.csproj", "Infra.Api/"]
2020-12-15T03:01:53.0455420Z  ---> 65683beda3cf
2020-12-15T03:01:53.0456191Z Step 12/30 : COPY ["Infra.Aws.Event/Infra.Aws.Event.csproj", "Infra.Aws.Event/"]
2020-12-15T03:01:54.0391012Z  ---> 6731f81a42bc
2020-12-15T03:01:54.0391573Z Step 13/30 : COPY ["Main/Device.Domain/Device.Domain.csproj", "Main/Device.Domain/"]
2020-12-15T03:01:55.0449753Z  ---> 3ecf269554ac
2020-12-15T03:01:55.0450404Z Step 14/30 : COPY ["Main/External.Domain/External.Domain.csproj", "Main/External.Domain/"]
2020-12-15T03:01:56.0430019Z  ---> 9ce91a97cab9
2020-12-15T03:01:56.0430864Z Step 15/30 : COPY ["Data.Mongo/Data.Mongo.csproj", "Data.Mongo/"]
2020-12-15T03:01:57.0468614Z  ---> bdc21db16d7e
2020-12-15T03:01:57.0490805Z Step 16/30 : COPY ["External.Domain.Data/External.Domain.Data.csproj", "External.Domain.Data/"]
2020-12-15T03:01:58.0441570Z  ---> a5fcf027a985
2020-12-15T03:01:58.0442053Z Step 17/30 : COPY ["Infra.Event/Infra.Event.csproj", "Infra.Event/"]
2020-12-15T03:01:59.0537842Z  ---> d28a427efd24
2020-12-15T03:01:59.0538339Z Step 18/30 : COPY ["Main/Files/Files.csproj", "Main/Files/"]
2020-12-15T03:02:00.0484332Z  ---> cb4dd49459eb
2020-12-15T03:02:00.0484797Z Step 19/30 : RUN dotnet restore "Main/Api/Api.csproj"
2020-12-15T03:02:00.1136284Z  ---> Running in 0d9c560c953b
2020-12-15T03:02:01.4171207Z   Determining projects to restore...
2020-12-15T03:02:04.2443619Z   Restored /src/Infra/Infra.csproj (in 1.68 sec).
2020-12-15T03:02:04.3372623Z   Restored /src/External.Domain.Data/External.Domain.Data.csproj (in 1.84 sec).
2020-12-15T03:02:05.0521974Z   Restored /src/Infra.Aws.Event/Infra.Aws.Event.csproj (in 707 ms).
2020-12-15T03:02:05.0539329Z   Restored /src/Infra.Event/Infra.Event.csproj (in 841 ms).
2020-12-15T03:02:05.0772560Z   Restored /src/DataModel/DataModel.csproj (in 19 ms).
2020-12-15T03:02:05.1036674Z   Restored /src/Data.Mongo/Data.Mongo.csproj (in 19 ms).
2020-12-15T03:02:06.4045177Z   Restored /src/Infra.Api/Infra.Api.csproj (in 1.34 sec).
2020-12-15T03:02:06.4045811Z   Restored /src/Main/Device.Domain/Device.Domain.csproj (in 1.29 sec).
2020-12-15T03:02:06.4852803Z   Restored /src/Main/External.Domain/External.Domain.csproj (in 72 ms).
2020-12-15T03:02:06.5325890Z   Restored /src/Main/Files/Files.csproj (in 72 ms).
2020-12-15T03:02:06.5606150Z   Restored /src/Main/Domain/Domain.csproj (in 67 ms).
2020-12-15T03:02:09.4765958Z   Restored /src/Main/Api/Api.csproj (in 2.98 sec).
2020-12-15T03:02:26.8771879Z Removing intermediate container 0d9c560c953b
2020-12-15T03:02:26.8773205Z  ---> 2ca8b96bc0f0
2020-12-15T03:02:26.8773598Z Step 20/30 : COPY . .
2020-12-15T03:02:28.2352798Z  ---> a4425ad66b6c
2020-12-15T03:02:28.2353547Z Step 21/30 : WORKDIR "/src/Main/Api"
2020-12-15T03:02:28.2726661Z  ---> Running in a2a95bab1cde
2020-12-15T03:02:29.4961959Z Removing intermediate container a2a95bab1cde
2020-12-15T03:02:29.4963400Z  ---> 25f52c163cc2
2020-12-15T03:02:29.4964353Z Step 22/30 : RUN dotnet build "Api.csproj" -c Release -o /app/build
2020-12-15T03:02:29.5491396Z  ---> Running in 6e625de830b0
2020-12-15T03:02:30.2633818Z Microsoft (R) Build Engine version 16.7.1+52cd83677 for .NET
2020-12-15T03:02:30.2634338Z Copyright (C) Microsoft Corporation. All rights reserved.
2020-12-15T03:02:30.2634557Z 
2020-12-15T03:02:30.7524833Z   Determining projects to restore...
2020-12-15T03:02:31.8471286Z   All projects are up-to-date for restore.
2020-12-15T03:02:34.3056821Z   Infra -> /app/build/Infra.dll
2020-12-15T03:02:34.7427324Z   DataModel -> /app/build/DataModel.dll
2020-12-15T03:02:35.0425314Z   Infra.Aws.Event -> /app/build/Infra.Aws.Event.dll
2020-12-15T03:02:35.6136637Z   Data.Mongo -> /app/build/Data.Mongo.dll
2020-12-15T03:02:35.7325011Z   Infra.Api -> /app/build/Infra.Api.dll
2020-12-15T03:02:35.7801144Z   Infra.Event -> /app/build/Infra.Event.dll
2020-12-15T03:02:36.1464908Z   Domain -> /app/build/Domain.dll
2020-12-15T03:02:36.2089423Z   External.Domain.Data -> /app/build/External.Domain.Data.dll
2020-12-15T03:02:36.6504907Z   External.Domain -> /app/build/External.Domain.dll
2020-12-15T03:02:37.0138801Z   Device.Domain -> /app/build/Device.Domain.dll
2020-12-15T03:02:37.0744375Z   Files -> /app/build/Files.dll
2020-12-15T03:02:37.9291706Z CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/Main/Api/Api.csproj]
2020-12-15T03:02:37.9402998Z 
2020-12-15T03:02:37.9403460Z Build FAILED.
2020-12-15T03:02:37.9403644Z 
2020-12-15T03:02:37.9404734Z CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/Main/Api/Api.csproj]
2020-12-15T03:02:37.9405166Z     0 Warning(s)
2020-12-15T03:02:37.9405380Z     1 Error(s)
2020-12-15T03:02:37.9405540Z 
2020-12-15T03:02:37.9405747Z Time Elapsed 00:00:07.60
2020-12-15T03:02:38.2431634Z The command '/bin/sh -c dotnet build "Api.csproj" -c Release -o /app/build' returned a non-zero code: 1
2020-12-15T03:02:38.2553689Z ##[error]The command '/bin/sh -c dotnet build "Api.csproj" -c Release -o /app/build' returned a non-zero code: 1
2020-12-15T03:02:38.2563694Z ##[error]The process '/usr/bin/docker' failed with exit code 1
2020-12-15T03:02:38.2568300Z ##[section]Finishing: Build an image

As shown in logs, the error happens on RUN dotnet build "Api.csproj" -c Release -o /app/build and the error states Program does not contain a static 'Main' method suitable for an entry point [/src/Main/Api/Api.csproj]

However, I noticed that under this part of the logs:

2020-12-15T03:02:30.7524833Z   Determining projects to restore...
2020-12-15T03:02:31.8471286Z   All projects are up-to-date for restore.
2020-12-15T03:02:34.3056821Z   Infra -> /app/build/Infra.dll
2020-12-15T03:02:34.7427324Z   DataModel -> /app/build/DataModel.dll
2020-12-15T03:02:35.0425314Z   Infra.Aws.Event -> /app/build/Infra.Aws.Event.dll
2020-12-15T03:02:35.6136637Z   Data.Mongo -> /app/build/Data.Mongo.dll
2020-12-15T03:02:35.7325011Z   Infra.Api -> /app/build/Infra.Api.dll
2020-12-15T03:02:35.7801144Z   Infra.Event -> /app/build/Infra.Event.dll
2020-12-15T03:02:36.1464908Z   Domain -> /app/build/Domain.dll
2020-12-15T03:02:36.2089423Z   External.Domain.Data -> /app/build/External.Domain.Data.dll
2020-12-15T03:02:36.6504907Z   External.Domain -> /app/build/External.Domain.dll
2020-12-15T03:02:37.0138801Z   Device.Domain -> /app/build/Device.Domain.dll
2020-12-15T03:02:37.0744375Z   Files -> /app/build/Files.dll

There should be another Api -> /app/build/Api.dll but there isn't. It seems that it fails to build into a dll with I don't know what is the error.

This only fails in the Azure DevOps release pipeline Build Docker Image task, the same project and Dockerfile runs and builds well in my local. Able to run the image local as well.

Below are my Dockerfile:

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

ENV ASPNETCORE_ENVIRONMENT #{environment-profile}#

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["Main/Api/Api.csproj", "Main/Api/"]
COPY ["Main/DMS.Domain/DMS.Domain.csproj", "Main/DMS.Domain/"]
COPY ["Infra.Api/Infra.Api.csproj", "Infra.Api/"]
COPY ["DataModel/DataModel.csproj", "DataModel/"]
COPY ["Infra/Infra.csproj", "Infra/"]
COPY ["Infra.Aws.Event/Infra.Aws.Event.csproj", "Infra.Aws.Event/"]
COPY ["Main/Device.Domain/Device.Domain.csproj", "Main/Device.Domain/"]
COPY ["Main/External.Domain/External.Domain.csproj", "Main/External.Domain/"]
COPY ["Data.Mongo/Data.Mongo.csproj", "Data.Mongo/"]
COPY ["External.Domain.Data/External.Domain.Data.csproj", "External.Domain.Data/"]
COPY ["Infra.Event/Infra.Event.csproj", "Infra.Event/"]
COPY ["Main/Files/Files.csproj", "Main/Files/"]
RUN dotnet restore "Main/Api/Api.csproj"
COPY . .

WORKDIR "/src/Main/Api"
RUN dotnet build "Api.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Api.dll", "--environment=#{environment-profile}#"]

Here is my project structure:

Open sln file:

- Main
  - Api
    - Api.csproj
  - Domain
    - Domain.csproj
  - Device.Domain
    - Device.Domain.csproj
  - External.Domain
    - External.Domain.csproj
  - Files
    - Files.csproj
- External.Domain.Data
  - External.Domain.Data.csproj
- Infra
  - Infra.csproj
- Infra.Api
  - Infra.Api.csproj
- Infra.Event
  - Infra.Event.csproj
- Infra.Aws.Event
  - Infra.Aws.Event.csproj
- DataModel
  - DataModel.csproj
- Data.Mongo
  - Data.Mongo.csproj
- Dockerfile

In my release pipeline, I've set the Dockerfile to $(System.DefaultWorkingDirectory)/_API-CI-Test/drop/Dockerfile and built context default to ** which is supposed to be a directory where dockerfile stays at, in this case, it would be the root directory.

After the Build Pipeline success, I can see my project directory and their .csproj file under their directory as well as Dockerfile in the artifacts under drop.

So I do not know what is the problem, I've done everything I can find but still not working. It doesn't build/restore the Api -> /app/build/Api.dll and I do not know why. FYI, the Api.csproj is the main project so inside it have a Main method. The Dockerfile is also generated based on this Api.csproj.

Hope anyone who knows what is wrong can give me some hints. Appreciate any help! Thanks!

Mar 18, 2022 in Other DevOps Questions by Kichu
• 19,050 points
3,376 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Other DevOps Questions

0 votes
0 answers
0 votes
0 answers

How to YML Schedule build in Azure DevOps Pipeline

I have an existing pipeline created in ...READ MORE

Mar 28, 2022 in Other DevOps Questions by Kichu
• 19,050 points
1,291 views
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,100 points
2,687 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP