0

I am trying to dockerize my Angular/WebApi application and with help from the community I have finally managed to build an image and being able to execute the image without errors in the console. But I am not able to navigate to my application using localhost.

My Dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2.105 AS build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY ["Fightplan_v1/Fightplan_v1.csproj", "Fightplan_v1/"]
COPY ["Fightplan_v1.Autogenerate/Fightplan_v1.Autogenerate.csproj", "Fightplan_v1.Autogenerate/"]
COPY ["Fightplan_v1.Autogenerate.Test/Fightplan_v1.Autogenerate.Test.csproj", "Fightplan_v1.Autogenerate.Test/"]
COPY ["Fightplan_v1.Database/Fightplan_v1.Database.csproj", "Fightplan_v1.Database/"]
COPY ["Fightplan_v1.Helpers/Fightplan_v1.Helpers.csproj", "Fightplan_v1.Helpers/"]
COPY ["Fightplan_v1.Jobs/ConvertImagestoBlob/Fightplan_v1.ConvertImagestoBlob.csproj", "Fightplan_v1.Jobs/ConvertImagestoBlob/"]
COPY ["Fightplan_v1.Models/Fightplan_v1.Models.csproj", "Fightplan_v1.Models/"]
COPY ["Fightplan_v1.Shared/Fightplan_v1.Shared.csproj", "Fightplan_v1.Shared/"]
RUN dotnet restore "Fightplan_v1/Fightplan_v1.csproj"

# Setup NodeJs
RUN apt-get update && \
    apt-get install -y wget && \
    apt-get install -y gnupg2 && \
    wget -qO- https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install -y build-essential nodejs

# Copy everything else and build
COPY . .
WORKDIR "/src/Fightplan_v1"
RUN dotnet build "Fightplan_v1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Fightplan_v1.csproj" -c Release -o /app/publish

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
COPY --from=publish /app/publish .

EXPOSE 80
ENTRYPOINT ["dotnet", "Fightplan_v1.dll"]

Running docker build -f .\fp.dockerfile -t test . creates an image without any errors. Running docker run -p 5100:80 -it test starts the image without any errors in the console: enter image description here but it gives an XmlKeyManager warning: enter image description here

When I try to go to http://localhost:5100 I get a ERR_CONNECTION_REFUSED in the browser and the console gives me this error: enter image description here

I have tried to go directly to 172.17.0.1 instead of localhost. I have also tried to use https instead of http but that didn't give me the unauthorized error as above which should mean that hitting http is correct but the Angular application is not rendered.

Everything works locally without docker. I am able to publish the application via dotnet commands in powershell: dotnet restore and dotnet publish. This will make the application run on https://localhost:5000.

Am I missing another step in the Dockerfile?

Casper Nybroe
  • 1,179
  • 3
  • 23
  • 47
  • Did you previously run this application locally on the same port? Try co clear all cookies for that domain in browser. This is related more to the IdentityServer configuration or/and angular app rather to the Docker, so to diagnose the problem some sources are required. This questions might be related: [Custom login UI for IdentityServer 4](https://stackoverflow.com/questions/53030506/custom-login-ui-for-identityserver-4) and [Identity Server 4 Claims empty on API](https://stackoverflow.com/questions/50197603/identity-server-4-claims-empty-on-api) – Ivvan Nov 18 '19 at 11:46
  • Hi @Ivvan, thank you for your comment. I have tried to run it in incognito but that didn't help. Everything works fine locally without docker. I have updated my question. :) – Casper Nybroe Nov 18 '19 at 12:03
  • This is definitely not a Docker problem anymore. Try to configure [DataProtection](https://stackoverflow.com/a/44461281/2041039). It is still hard to recommend anything without actual code. Is your application need an authorization from the start? Check, if it redirects to correct login page (locally you are using https, so, if auth always redirect you to https, inside docker it will fails, because only http is configured). Also what king of auth you are using - cookie/jwt/other? – Ivvan Nov 18 '19 at 13:27
  • The root page and many other routes doesn't require login. I am using JWT. I will try changing the loca config of https to http and get back to you. – Casper Nybroe Nov 18 '19 at 14:06
  • @Ivvan, this had something to do with a forced redirect. I posted the answer. Thank you for your help. – Casper Nybroe Nov 21 '19 at 09:57

1 Answers1

1

This was quite hidden but completely my own fault. I had a app.UseHttpsRedirection() in Startup.cs. I removed this and everything worked.

Casper Nybroe
  • 1,179
  • 3
  • 23
  • 47