C
C#2y 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
TempticaOP2y 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
rhymbit2y 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
TempticaOP2y ago
well yes, API just has references to the BLL and BLL to DAL
rhymbit
rhymbit2y ago
awesome, then try that dockerfile
Temptica
TempticaOP2y ago
ah I see, just build, then get teh DLL of the API?
rhymbit
rhymbit2y ago
you see that COPY line, it just copies built files into the container image
Temptica
TempticaOP2y ago
makes sense! thank you I'll try it out first sighh port already in use... Gotta love it
rhymbit
rhymbit2y 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
TempticaOP2y ago
yeah, had this in college thought I'd never use it, look at me now kekw
Temptica
TempticaOP2y ago
Temptica
TempticaOP2y ago
somehow uses 1433 ah nvm I see why DB uses it
Temptica
TempticaOP2y ago
where does it get "MyApp.dll" from?
rhymbit
rhymbit2y 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
Jimmacle2y ago
a dockerfile that doesn't actually build the application pepethink
Temptica
TempticaOP2y ago
I did, thats why I'm confused and yes I did save the file 😄
rhymbit
rhymbit2y 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
TempticaOP2y 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
TempticaOP2y ago
when I navigate to the port, the terminal gives this and then a huge amount of db related lines
rhymbit
rhymbit2y 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
Kays2y ago
Hi, Did you generate the Dockerfile with your IDE or did u create it in your own ?
Temptica
TempticaOP2y 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
rhymbit2y 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
TempticaOP2y ago
maybe I didn't publish it and only build it, maybe thats why it doesn't work 😅
Temptica
TempticaOP2y ago
I disserved that one haha
Kays
Kays2y ago
Well that's true. publish folder harold
Temptica
TempticaOP2y 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
Kays2y 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
TempticaOP2y ago
well, the app works now how Pratt explained except for my db doing weird stuff
Accord
Accord2y 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.
Want results from more Discord servers?
Add your server