C# 在docker上获取asp.net核心web API应用程序值的问题

C# 在docker上获取asp.net核心web API应用程序值的问题,c#,api,docker,asp.net-core,ubuntu-18.04,C#,Api,Docker,Asp.net Core,Ubuntu 18.04,我创建了一个简单的asp.net核心web API应用程序,其中包含Dockerfile,如下所示: FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env COPY . /app WORKDIR /app RUN ["dotnet","restore"] RUN ["dotnet","build"] EXPOSE 5000/tcp ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore",

我创建了一个简单的asp.net核心web API应用程序,其中包含Dockerfile,如下所示:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
COPY . /app
WORKDIR /app
RUN ["dotnet","restore"]
RUN ["dotnet","build"]
EXPOSE 5000/tcp
ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "https://0.0.0.0:5000"]
我在终端上执行此命令
docker build-t dockersample22.
,得到以下结果:

Sending build context to Docker daemon  1.702MB
Step 1/7 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
 ---> 08657316a4cd
Step 2/7 : COPY . /app
 ---> a54d73690d28
Step 3/7 : WORKDIR /app
 ---> Running in b93e13c06868
Removing intermediate container b93e13c06868
 ---> 1754614c722c
Step 4/7 : RUN ["dotnet","restore"]
 ---> Running in d648867be4cc
  Restore completed in 525.79 ms for /app/DockerSample2.csproj.
Removing intermediate container d648867be4cc
 ---> 91196986565c
Step 5/7 : RUN ["dotnet","build"]
 ---> Running in 6d5b137f97e4
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 41.58 ms for /app/DockerSample2.csproj.
  DockerSample2 -> /app/bin/Debug/netcoreapp2.2/DockerSample2.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.28
Removing intermediate container 6d5b137f97e4
 ---> 21af5bda0bbc
Step 6/7 : EXPOSE 5000/tcp
 ---> Running in 138c20830b2e
Removing intermediate container 138c20830b2e
 ---> 186a88f4bc00
Step 7/7 : ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "https://0.0.0.0:5000"]
 ---> Running in 936a9ae2de21
Removing intermediate container 936a9ae2de21
 ---> b2dc6e76c9a1
Successfully built b2dc6e76c9a1
Successfully tagged dockersample22:latest
watch : Polling file watcher is enabled
watch : Started
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
      Creating key {9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448} with creation date 2019-09-10 20:04:06Z, activation date 2019-09-10 20:04:06Z, and expiration date 2019-12-09 20:04:06Z.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
      Writing data to file '/root/.aspnet/DataProtection-Keys/key-9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448.xml'.
Hosting environment: Development
Content root path: /app
Now listening on: https://0.0.0.0:5000
Application started. Press Ctrl+C to shut down.
然后我执行命令
docker run-p 5000:5000 dockersample22
我得到以下结果:

Sending build context to Docker daemon  1.702MB
Step 1/7 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
 ---> 08657316a4cd
Step 2/7 : COPY . /app
 ---> a54d73690d28
Step 3/7 : WORKDIR /app
 ---> Running in b93e13c06868
Removing intermediate container b93e13c06868
 ---> 1754614c722c
Step 4/7 : RUN ["dotnet","restore"]
 ---> Running in d648867be4cc
  Restore completed in 525.79 ms for /app/DockerSample2.csproj.
Removing intermediate container d648867be4cc
 ---> 91196986565c
Step 5/7 : RUN ["dotnet","build"]
 ---> Running in 6d5b137f97e4
Microsoft (R) Build Engine version 16.2.32702+c4012a063 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 41.58 ms for /app/DockerSample2.csproj.
  DockerSample2 -> /app/bin/Debug/netcoreapp2.2/DockerSample2.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:02.28
Removing intermediate container 6d5b137f97e4
 ---> 21af5bda0bbc
Step 6/7 : EXPOSE 5000/tcp
 ---> Running in 138c20830b2e
Removing intermediate container 138c20830b2e
 ---> 186a88f4bc00
Step 7/7 : ENTRYPOINT [ "dotnet", "watch", "run", "--no-restore", "--urls", "https://0.0.0.0:5000"]
 ---> Running in 936a9ae2de21
Removing intermediate container 936a9ae2de21
 ---> b2dc6e76c9a1
Successfully built b2dc6e76c9a1
Successfully tagged dockersample22:latest
watch : Polling file watcher is enabled
watch : Started
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[58]
      Creating key {9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448} with creation date 2019-09-10 20:04:06Z, activation date 2019-09-10 20:04:06Z, and expiration date 2019-12-09 20:04:06Z.
warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
      No XML encryptor configured. Key {9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448} may be persisted to storage in unencrypted form.
info: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[39]
      Writing data to file '/root/.aspnet/DataProtection-Keys/key-9a0a6b08-cebd-41ed-91b9-aa4bbe8c6448.xml'.
Hosting environment: Development
Content root path: /app
Now listening on: https://0.0.0.0:5000
Application started. Press Ctrl+C to shut down.
当我发送请求时
http://0.0.0.0:5000/api/values
http://localhost:5000/api/values
,我没有任何结果。
我检查docker容器,我的容器正在运行,那么为什么它不返回响应呢?

应用程序说它正在侦听
https
,但是你正在使用
http
来处理你发送的请求。thans@KirkLarkin,但是我发送
https
请求,它的工作方式与https的结果不一样吗?“我想会有一个证书信任问题。”柯克拉金是真的,我通过
邮递员
发出请求说它不起作用。当我关闭
SSL证书验证
设置
Postman
它的工作时,非常感谢