Reputation: 443
I'm trying to dockerize my .net core rest api app.
I refer to MS Menual which give docker sample and commands guidance and It worked well.
So, to try [dockerizing] myself, I created .Net Core Rest API app and checked 'Use Docker Support'.
I built image with 'Dockerfile' had been given by MS. Below is Dockerfile
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["dockersupport.csproj", ""]
RUN dotnet restore "./dockersupport.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "dockersupport.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "dockersupport.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "dockersupport.dll"]
And I build it with
>$ docker build -t docksupport .
And run with
>$ docker run --rm -it -p 5000:80 --name dockersupport dockersupport
And server was running well. However I can't access to API swagger page.
When I tried to build/run with visual studio only, It showed swagger page well.
I tried to access to web page with url : 'localhost:5000/swagger/index.html' docker and local both.
I can't understand why MS sample app works well but my app doesn't. I wonder what is the differece between their and mine.
Would you share your knowledge or how can I access web page of my app?
Upvotes: 2
Views: 1301
Reputation: 443
In my code, swagger UI would be shown if environment is Development. However, I just set my docker environment Production.
I refer to this post Swagger UI gives 404 when app is running in Docker container and I deleted if condition, It works well
Upvotes: 3