Need assistance with Dockerfile and Kubernetes for .AspNetCore service Need assistance with Dockerfile and Kubernetes for .AspNetCore service kubernetes kubernetes

Need assistance with Dockerfile and Kubernetes for .AspNetCore service


Leandro's comments helped come across the solution.

So first a rundown of that COPY command, it takes two parameters, source and destination. Within the template for the Dockerfile for Visual Studio, it includes the folder location of the .csproj file it is attempting to copy. In my case, the command read as follows:

COPY ["Aeros.Services.Kubernetes/Aeros.Services.Kubernetes.csproj", "Aeros.Services.Kubernetes/"]

So it is looking for my Aeros.Services.Kubernetes.csproj file in the Aeros.Services.Kubernetes project folder and copying it to the Aeros.Services.Kubernetes folder in the src folder of Docker.

The problem with this is that if you use the default setup, your dockerfile is included inside the project folder. If you are executing the docker build from within the project folder, the syntax for the COPY command is actually looking in the wrong file location. For instance, if your project is TestApp.csproj located in the TestApp project folder, and you are executing the Docker build command for the dockerfile within the same folder, the syntax for that COPY command:

COPY ["TestApp/TestApp.csproj", "TestApp/"]

is actually looking for: TestApp/TestApp/TestApp.csproj.

The correct syntax for the COPY command in this situation should be:

COPY ["TestApp.csproj", "TestApp/"]

since you are already within the TestApp project folder.

Another problem with the default template that may trouble some is that it doesn't copy the web files for the project either, so once you get past the COPY and dotnet restore steps, you will fail during the BUILD with a:

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

This is resolved by adding:

COPY . ./

following your RUN dotnet restore command to copy your files.

Once these pieces have been addressed in the default template provided, everything should be functioning as expected.

Thanks for the help!


In which line the problem happens? I do not remember if docker build shows it.

Where are you executing this build? The problem is that it is not finding the file you are trying to copy. It should be local to where the command is executed.

I saw now, the problem is on the first COPY.