0
votes

I used Visual Studio 2017 and created a Web API app with docker (Linux) support. And it gave the following message when running.

PS C:\> docker run hack2
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {93297fb1-e111-46f6-91e1-1bb4878a3941} may be persisted to storage in unencrypted
 form.
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.

Here is the scaffolded Docker file.

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["hack2/hack2.csproj", "hack2/"]
RUN dotnet restore "hack2/hack2.csproj"
COPY . .
WORKDIR "/src/hack2"
RUN dotnet build "hack2.csproj" -c Release -o /app

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "hack2.dll"]

When trying in the local Windows 10 PC, it shows

$ curl localhost/api/values
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0curl: (7) Failed to connect to localhost port 80: Connection refused

And then I copied the image to a Linux box and tried to curl

curl localhost/api/values
<HTML><HEAD>
<TITLE>Request Error</TITLE>
</HEAD>
<BODY>
<FONT face="Helvetica">
<big><strong></strong></big><BR>
</FONT>
<blockquote>
<TABLE border=0 cellPadding=1 width="80%">
<TR><TD>
<FONT face="Helvetica">
<big>Request Error (invalid_request)</big>
<BR>
<BR>
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
Your request could not be processed. Request could not be handled
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica">
This could be caused by a misconfiguration, or possibly a malformed request.
</FONT>
</TD></TR>
<TR><TD>
<FONT face="Helvetica" SIZE=2>
<BR>
For assistance, contact your network support team.
</FONT>
</TD></TR>
</TABLE>
</blockquote>
</FONT>
</BODY></HTML>
1
Have you tried with the 2.1 sdk image instead?Stark

1 Answers

0
votes

Is port 80 available on your box (not used by default web server?)

Try docker run -p 80:80 hack2

Check Docker docs for docker run --publish for details how to share port with a host machine.