❔ 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
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
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
@Temptica
well yes, API just has references to the BLL and BLL to DAL
awesome, then try that dockerfile
ah I see, just build, then get teh DLL of the API?
you see that
COPY
line, it just copies built files into the container imagemakes sense!
thank you
I'll try it out first port already in use... Gotta love it
also use the docker compose
you know how to use it? @Temptica
yeah, had this in college
thought I'd never use it, look at me now
somehow uses 1433
ah nvm I see why
DB uses it
where does it get "MyApp.dll" from?
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 ?a dockerfile that doesn't actually build the application
I did, thats why I'm confused
and yes I did save the file 😄
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
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
when I navigate to the port, the terminal gives this and then a huge amount of db related lines
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?Hi, Did you generate the Dockerfile with your IDE or did u create it in your own ?
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
you don't ?
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 foldermaybe I didn't publish it and only build it, maybe thats why it doesn't work 😅
I disserved that one haha
Well that's true. publish folder
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
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
well, the app works now how Pratt explained
except for my db doing weird stuff
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.