C
C#15mo ago
Temptica

❔ Docker file for Multi-layered project

I have a solution with 3 projects: One being an asp.net core web api, and the other 2 being class projects. I've been following a tutorial and my main APi project works just fine, it's the other 2 that don't, I've tried multiple paths (one with ../, one without) but nothing seems to work. Thank you in advance
30 Replies
Temptica
Temptica15mo ago
and yes the DAL is missing the "API" in the name, that's correct, don't know how that happened but the folder name is missing that
rhymbit
rhymbit15mo ago
Is the API project all you need ultimately? I mean, does the API project reference the other two & uses them, and ultimately you just want to run the api in a docker container? Because then you can build the API project outside of the docker and just copy the built files inside the container and just run the project
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish/ app/
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://*:5000
ENTRYPOINT ["dotnet", "MyApp.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:6.0
COPY bin/Release/net6.0/publish/ app/
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://*:5000
ENTRYPOINT ["dotnet", "MyApp.dll"]
@Temptica
Temptica
Temptica15mo ago
well yes, API just has references to the BLL and BLL to DAL
rhymbit
rhymbit15mo ago
awesome, then try that dockerfile
Temptica
Temptica15mo ago
ah I see, just build, then get teh DLL of the API?
rhymbit
rhymbit15mo ago
you see that COPY line, it just copies built files into the container image
Temptica
Temptica15mo ago
makes sense! thank you I'll try it out first sighh port already in use... Gotta love it
rhymbit
rhymbit15mo ago
also use the docker compose
version: "3.8"

services:
server:
build: .
ports:
- "5000:5000"
version: "3.8"

services:
server:
build: .
ports:
- "5000:5000"
you know how to use it? @Temptica
Temptica
Temptica15mo ago
yeah, had this in college thought I'd never use it, look at me now kekw
Temptica
Temptica15mo ago
Temptica
Temptica15mo ago
somehow uses 1433 ah nvm I see why DB uses it
Temptica
Temptica15mo ago
where does it get "MyApp.dll" from?
rhymbit
rhymbit15mo ago
from that path in COPY, in the dockerfile that I posted earlier also, did you not change the app name from MyApp.dll to whatever your app name is when ?
Jimmacle
Jimmacle15mo ago
a dockerfile that doesn't actually build the application pepethink
Temptica
Temptica15mo ago
I did, thats why I'm confused and yes I did save the file 😄
rhymbit
rhymbit15mo ago
what's wrong now? same thing? maybe try deleting the image & building the whole thing again maybe it's using some cache layer that it shouldn't
Temptica
Temptica15mo ago
that fixed it waiting for it to be fully started, I'll keep you updated if it fully work snow Doesn't seem to work, I simply end up with "This page isn't working, localhost didn’t send any data. ERR_EMPTY_RESPONSE" when navigating to localhost:5000 I also tried with port 80 just in case but no result
Temptica
Temptica15mo ago
when I navigate to the port, the terminal gives this and then a huge amount of db related lines
rhymbit
rhymbit15mo ago
did you check if your built files work outside the container itself? I mean your published app does that work? if you go to bin/Release/net6.0/publish/ and run dotnet My_App_Name.dll, does it work as expected?
Kays
Kays15mo ago
Hi, Did you generate the Dockerfile with your IDE or did u create it in your own ?
Temptica
Temptica15mo ago
well, it generated it for me but I've commented that out 🙂 the generated one didn't even work for my api itself so paths were incorrect somehow thats a fair point and I'm impressed I didn't even think of that I actually don't have a /publish folder, it's all in the net6.0, and thats also what I set in teh docker file but no, 5000 nor 5001 seem to work odd enough
rhymbit
rhymbit15mo ago
you don't weird ? even if you use VS to "publish" your app, the final built app ends up inside a folder called "publish" I sometimes do it with cli dotnet publish -c Release obviously it won't if you change the name of the folder
Temptica
Temptica15mo ago
maybe I didn't publish it and only build it, maybe thats why it doesn't work 😅
Temptica
Temptica15mo ago
I disserved that one haha
Kays
Kays15mo ago
Well that's true. publish folder harold
Temptica
Temptica15mo ago
and still doesn't work 😬 5000 gives me a not found error, 5001 gives me empty response oh I'm an idiot it'd be really cool if I would add /swagger/index.html wouldn't it
Kays
Kays15mo ago
The following Dockerfile is working fine for me : FROM mcr.microsoft.com/dotnet/aspnet:7.0.2-jammy AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY ["Project.API/Project.API.csproj", "Project.API/"] COPY ["Project.Library/Project.Library.csproj", "Project.Library/"] RUN dotnet restore "Project.API/Project.API.csproj" COPY . . WORKDIR "/src/Project.API" RUN dotnet build "Project.API.csproj" -c Release -o /app FROM build AS publish RUN dotnet publish "ProjectAPI.csproj" -c Release -o /app FROM base AS final WORKDIR /app COPY --from=publish /app . ENTRYPOINT ["dotnet", "Project.API.dll"] . . The dockerfile is in the root of my solution with projects Solution Structure : - Project.API - .... - Project.API.csproj - Project.Library - .... - Project.Library.csproj -Dockerfile
Temptica
Temptica15mo ago
well, the app works now how Pratt explained except for my db doing weird stuff
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.