0

I am very new to docker and am confused with how to make a docker image of my project. It's an ASP.NET Core app with 4 different projects: API, Domain layer, Business Logic layer, Data Access Layer. Root folder looks like this: Root folder Each folder that starts with "Library" contains a .csproj file. The question is, where do I put Dockerfile(s) and what do I write there?

I tried putting it in the root folder and after multiple attempts I managed to write something like this:

FROM mcr.microsoft.com/dotnet/sdk AS build
WORKDIR /app
COPY *.sln .
COPY ./LibraryAPI/*.csproj ./LibraryAPI/LibraryAPI.csproj
COPY ./Library.DAL/*.csproj ./Library.DAL/Library.DAL.csproj
COPY ./Library.BLL/*.csproj ./Library.BLL/Library.BLL.csproj
COPY ./Library.Domain/*.csproj ./Library.Domain/Library.Domain.csproj

RUN dotnet restore "./LibraryAPI/LibraryAPI.csproj"

COPY . ./
RUN dotnet publish -c release -o out

FROM mcr.microsoft.com/dotnet/aspnet
WORKDIR /app
COPY --from=build /app/out .
EXPOSE 1433
ENTRYPOINT ["dotnet", "LibraryAPI.dll"]

It is a Frankenstein's monster of different google searches and it builds successfully as well as the container runs. But all I get when requesting http://localhost:1433/ is ERR_EMPTY_RESPONSE. Another thing is database. It is a lot to ask for a complete solution but I really need recommendations or any hints on where and how to structure those Dockerfiles as every source I found tells different stuff. I just need it to launch a local server with a sqlserver database so that requests work. Thanks.

Alright, I was able to make Dockerfile prettier:

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /source
COPY . .
RUN dotnet restore "./LibraryAPI/LibraryAPI.csproj" --disable-parallel
RUN dotnet publish "./LibraryAPI/LibraryAPI.csproj" -c release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./
EXPOSE 5000
ENTRYPOINT ["dotnet","LibraryAPI.dll"]

It still does the same as before: sends ERR_EMPTY_RESPONSE, but it's better I suppose.

Telyonok
  • 3
  • 3

0 Answers0