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:
but it gives an
XmlKeyManager
warning:
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:
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?