0

I am trying to successfully build/publish a project using a dockerfile. However, for some reason it cannot find the output folder that it should of created. From the other posts, everything looks correct in my docker file.

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:5.0 as build
WORKDIR /app
COPY . .

RUN dotnet restore
RUN dotnet publish ./ClassLibrary2.csproj -c Release -o out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "ClassLibrary2.dll"]

Directory

enter image description here

Docker Command(ran from the folder where the docker file lies): docker build -f Dockerfile-SignedAssembly -t signed-assembly . Output:

enter image description here

Updated Image with missing bat file enter image description here

TheProgrammer
  • 1,314
  • 5
  • 22
  • 44
  • 1
    You can't run a class library, because it doesn't contain a suitable Main method. Try using the `console` template to start from instead. – Hans Kilian Mar 17 '22 at 20:58
  • @HansKilian Sorry what’s the console template? I can also test using an console app. – TheProgrammer Mar 17 '22 at 21:10
  • 1
    It's what you get if you do `dotnet new console` instead of `dotnet new classlib`. It looks like you use Visual Studio. I don't know how to get it from in there. – Hans Kilian Mar 17 '22 at 21:14
  • @HansKilian thanks for the advice! Will try that – TheProgrammer Mar 17 '22 at 21:20
  • @HansKilian Thanks! it works with the ConsoleApp. One last question, I am trying to run a post build event which is within my .net project already. It needs to run a batch file however docker is saying that the file cannot be found in the /app directory. When I list the files in the directory before the publish it says it is there. (See screenshot of error) – TheProgrammer Mar 17 '22 at 23:17
  • 1
    You are trying to run a `.bat` file in a Linux environment. That's not going to work, Linux doesn't support that. just like it can't run Windows executables (`.exe`) files. You could try using a shell script (`.sh`) instead. – omajid Mar 18 '22 at 15:00

1 Answers1

0

just replace COPY --from=build /app/out . by COPY --from=build /out . as shown below

FROM mcr.microsoft.com/dotnet/sdk:5.0 as build
WORKDIR /app
COPY . .

RUN dotnet restore
RUN dotnet publish ./ClassLibrary2.csproj -c Release -o /out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:5.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["dotnet", "ClassLibrary2.dll"]
xfusion
  • 3
  • 2