I am fairly new to Docker, and I'm trying to build a multi project Api solution dockerfile.
After trying out a huge amount of different ways, I have now tried this solution:
https://stackoverflow.com/a/49728860
This is my project layout:
/MainFolder
---Dockerfile
--- Projectname.sln
/Projectname.Api
--- Projectname.Api.csproj
--- code files
/Projectname.Models (api project has dependency of this project)
--- Projectname.Models.csproj
--- code files
/Projectname.Services (api project has dependency of this project)
--- Projectname.Services.csproj
--- code files
This is the current Dockerfile contents:
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS base
WORKDIR /app
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS http://*:5000
EXPOSE 5000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS builder
ARG Configuration=Release
WORKDIR /src
COPY *.sln ./
COPY Projectname.Api/Projectname.Api.csproj Projectname.Api/
COPY Projectname.Models/Projectname.Models.csproj Projectname.Models/
COPY Projectname.Services/Projectname.Services.csproj Projectname.Services/
RUN dotnet restore
COPY . .
WORKDIR /src/Projectname.Api
RUN dotnet build -c $Configuration -o /app
FROM builder AS publish
ARG Configuration=Release
RUN dotnet publish -c $Configuration -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Projectname.Api.dll"]
Note that the solution contains other projects as well, that the API-project is NOT dependent on.
Should I have the Dockerfile in the Api-project folder? Or is it best practice to keep it in the solution folder when you have dependent projects?
After docker build and Docker run -it -p 5000:80 myusername/projectname.api
I now get this confirmation:
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
But when I browse https://localhost/swagger or http://localhost:5000/swagger, I there is no response.