我怎样才能经营一家公司。容器中的NET Web API?
以下是我所做的:
我创造了一个
foo
文件夹
2在文件夹内,我打开一个终端并运行命令
dotnet new webapi
.然后我运行
dotnet run
并验证了通过浏览器可以访问该招摇。
3.补充
Dockerfile
到
福
文件夹:
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY ./ ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "foo.dll"]
4.执行
docker build -t aspnetapp .
命令
5去了
Properties/launchSettings.json
并找到了
profiles.foo.applicationUrl
(我使用该值通过浏览器2访问swagger来验证应用程序是否有效)。价值是
https://localhost:7055;http://localhost:5062
:
6.执行
docker run -d -p 8080:7055
命令
7.现在我转到浏览器
https://localhost:8080/swagger
期待着看到招摇过市的页面,但我什么也没看到:
我还想做什么:
-
在6中,我尝试将命令更改为
docker run -d -p 8080:5062
-
我检查了控制台上启动的应用程序,出于某些原因,它指的是第80个端口:
{"EventId":14,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Now listening on: http://[::]:80","State":{"Message":"Now listening on: http://[::]:80","address":"http://[::]:80","{OriginalFormat}":"Now listening on: {address}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Application started. Press Ctrl\u002BC to shut down.","State":{"Message":"Application started. Press Ctrl\u002BC to shut down.","{OriginalFormat}":"Application started. Press Ctrl\u002BC to shut down."}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Hosting environment: Production","State":{"Message":"Hosting environment: Production","envName":"Production","{OriginalFormat}":"Hosting environment: {envName}"}}
{"EventId":0,"LogLevel":"Information","Category":"Microsoft.Hosting.Lifetime","Message":"Content root path: /app/","State":{"Message":"Content root path: /app/","contentRoot":"/app/","{OriginalFormat}":"Content root path: {contentRoot}"}}
如何使容器中运行的应用程序可以通过浏览器访问?也就是说,我怎样才能看到大摇大摆的样子,并通过浏览器调用端点?