<p>I am trying to build a docker image for dotnet core app on windows which I am planning to host it on Kubernetes </p>

<p>with following details</p>

<pre><code>#docker file

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 8989

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["amazing-app.csproj", "amazing-app/"]
RUN dotnet restore "amazing-app/amazing-app.csproj"
COPY . .
WORKDIR "/src/amazing-app"
RUN dotnet build "amazing-app.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "amazing-app.dll"]
</code></pre>

<p>directory Structure is >></p>

<p><a href="https://i.stack.imgur.com/eB3af.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eB3af.png" alt="enter image description here"></a></p>

<p>After running <code>docker build -t amazing-app-one .</code> I am getting following error at step 10/16. Application builds &amp; runs locally but docker is not able to build image out of it.</p>

<pre><code>$&gt; &lt;Path&gt;\amazing-app&gt;docker build -t amazing-app-one .
Sending build context to Docker daemon  5.741MB
Step 1/16 : FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
 ---&gt; 08096137b740
Step 2/16 : WORKDIR /app
 ---&gt; Running in 14f5f9b7b3e5
Removing intermediate container 14f5f9b7b3e5
 ---&gt; ae4846eda3f7
Step 3/16 : EXPOSE 8989
 ---&gt; Running in 0f464e383641
Removing intermediate container 0f464e383641
 ---&gt; 6b855b84749e
Step 4/16 : FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
 ---&gt; 9817c25953a8
Step 5/16 : WORKDIR /src
 ---&gt; Running in 5a8fc99a3ecf
Removing intermediate container 5a8fc99a3ecf
 ---&gt; 694d5063e8e6
Step 6/16 : COPY ["amazing-app.csproj", "amazing-app/"]
 ---&gt; 450921f630c3
Step 7/16 : RUN dotnet restore "amazing-app/amazing-app.csproj"
 ---&gt; Running in ddb564e875be
  Restore completed in 1.81 sec for /src/amazing-app/amazing-app.csproj.
Removing intermediate container ddb564e875be
 ---&gt; b59e0c1dfb4d
Step 8/16 : COPY . .
 ---&gt; 695977f3b543
Step 9/16 : WORKDIR "/src/amazing-app"
 ---&gt; Running in aa5575c99ce3
Removing intermediate container aa5575c99ce3
 ---&gt; 781b4c552434
Step 10/16 : RUN dotnet build "amazing-app.csproj" -c Release -o /app/build
 ---&gt; Running in 3a602c34b5a9
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 36.78 ms for /src/amazing-app/amazing-app.csproj.
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/amazing-app/amazing-app.csproj]

Build FAILED.

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/amazing-app/amazing-app.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.37
The command '/bin/sh -c dotnet build "amazing-app.csproj" -c Release -o /app/build' returned a non-zero code: 1
</code></pre>

<p>find the source code on <a href="https://github.com/Kundan22/amazing-app/tree/master/amazing-app" rel="nofollow noreferrer">github link</a></p>

<p>am I missing something here? any help much appreciated.</p>

Kundan
<p>The issue is in folder structure. You copied your source to <code>/src</code> folder (see line 8 and 11 of Dockerfile), but *.csproj file is copied to <code>amazing-app</code> subfolder. </p>

<p>You can check it by running "intermediate" image, eg: <code>781b4c552434</code> (it is a hash of image before crash), like following: <code>docker run -it --rm --name xxx b5a968c1103c bash</code> and then you can inspect file system by <code>ls</code> command to see that source code and csproj file are located in different places.</p>

<p>So, i suggest to move Dockerfile to root directory (close to .dockerignore) and update path to csproj file (also, you need to run <code>docker build</code> command from root directory. This Dockerfile should work:</p>

<pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 8989

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["amazing-app/amazing-app.csproj", "amazing-app/"]
RUN dotnet restore "amazing-app/amazing-app.csproj"
COPY . .
WORKDIR "/src/amazing-app"
RUN dotnet build "amazing-app.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "amazing-app.dll"]
</code></pre>
