拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 如何从命令列运行VisualStudio生成的ASP.NETCore示例Web应用Docker映像?

如何从命令列运行VisualStudio生成的ASP.NETCore示例Web应用Docker映像?

白鹭 - 2022-02-24 1962 0 0

我有

  1. 分叉了planetaryDocs项目(一个示例服务器常驻Blazor Web 应用程序),
  2. 使用 Visual Studio 2022 创建 docker 容器
  3. 运行那个 docker 容器(通过 Visual Studio)和

并且 Visual Studio 会弹出一个指向 Web 服务器的浏览器,它似乎作业正常。

当我这样做时,docker image ls我看到了planetarydocs 影像。

我想试验 docker run 命令列。我怎么做?我停止了 Visual Studio docker 容器并

docker.exe run planetarydocs  -p 9090:80

这不起作用。

我将浏览器指向 http://localhost:9090,浏览器显示“无法访问此页面”。

我究竟做错了什么?

谢谢!

这是使用上述 docker 命令显示的内容:

   {"EventId":35,"LogLevel":"Warning","Category":"Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager","Message":"No XML encryptor configured. Key {3df3c08f-884d-49fe-a4f8-163ea6058090} may be persisted to storage in unencrypted form.","State":{"Message":"No XML encryptor configured. Key {3df3c08f-884d-49fe-a4f8-163ea6058090} may be persisted to storage in unencrypted form.","KeyId":"3df3c08f-884d-49fe-a4f8-163ea6058090","{OriginalFormat}":"No XML encryptor configured. Key {KeyId:B} may be persisted to storage in unencrypted form."}}
   {"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}"}}

2021 年 12 月 31 日星期五更新

好吧,我很尴尬:这行得通!

docker.exe run -p 9090:80 planetarydocs

如果docker run给我一个提示,我的开关订购错误,那就太好了……

有人可以指出我在launchsettings.json中描述docker的这种有趣语法的档案吗?

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "publishAllPorts": true,
  "useSSL": true
}
  1. 我一直在查看 appsettings.json 和 launchsettings.json 认为 docker 的埠应该在那里,但他们没有。ServicePortServiceHostscheme定义在哪里

  2. 这与 Visual Studio 每次从 docker 容器启动应用程序时都使用新埠这一事实有关吗?为什么这样做?

  3. 由于埠 80 有效,不应该在这些组态档中的某处定义埠 80 吗?

  4. 谁使用此启动设定组态档?只有 Visual Studio?如果我们从命令列运行 docker,我想我们会忽略组态档吗?

uj5u.com热心网友回复:

你的运行命令是错误的。Docker 的任何自变量都需要放在映像名称之前。影像名称后的任何自变量都会覆写影像中的任何 CMD 定义。

所以代替

docker.exe run planetarydocs  -p 9090:80

你应该做

docker.exe run -p 9090:80 planetarydocs

uj5u.com热心网友回复:

从您指向的存盘库中,该应用程序似乎使用埠 8081。

PlanetaryDocs/appsettings.json

"EndPoint": "https://localhost:8081/",

如果您没有更改它,请改用该埠尝试此命令

docker.exe run planetarydocs  -p 9090:8081
标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *