Visual Studio 中的 ASP.Net core 自定义 docker 卷挂载

问题描述 投票:0回答:2

最初我使用的是 Visual Studio 2017 Tools for Docker,因为这是早期版本的 Visual Studio 向 ASP.NET 添加 docker 支持时的默认设置。

最近我升级到 Visual Studio 2017 15.8.0 Preview 2,我注意到有一种全新的方法使用

launchSettings.json
进行 docker 构建。

旧方法有一个特殊的

*.dcproj
,whos项目的SDK属性指向
<Project Sdk="Microsoft.NET.Sdk.Web">
。在这个项目中,有一个
docker-compose.yml
和一个
docker-compose.override.yml
指向我的 ASP.Net 的
Dockerfile
。这非常灵活,允许我进行大量定制,例如添加卷安装,如下所示。

docker-compose.override.yml:

version: '3.5'
services:
  sample.container:
    volumes:
    - type: bind
      source: C:\config
      target: /config
      read_only: true
      volume:
        nocopy: true

这很棒,因为它允许我在调试期间轻松指向不在容器中的配置文件。

现在,在 Visual Studio 中使用新的 docker 工具,在

launchSettings.json
文件中使用
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="0.2.1686908" />
*.csproj
时,不再使用 compose 文件,它会直接启动
Dockerfile
。以下是我的
launchSettings.json
的副本。

我真的希望有人能告诉我如何以这种新方式将自定义卷挂载添加到

launchSettings.json
文件中,请参阅下面的
Docker
部分。

launchSettings.json:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:55836",
      "sslPort": 44354
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication1": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://localhost:{ServicePort}"
    }
  }
}

我还想说,我已经寻找这个问题的解决方案几个小时了,但我无法找到有关该主题的任何信息。

visual-studio docker asp.net-core
2个回答
21
投票

有几个 MSBuild 属性可用于增强 Docker 映像的构建/运行:

  • DockerfileBuildArguments
    :传递给 Docker 构建命令的附加参数。
  • DockerfileRunArguments
    :传递给 Docker 运行命令的附加参数。

示例:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <DockerfileRunArguments>-v "C:\HostFolder:/ContainerFolder:ro"</DockerfileRunArguments>
  </PropertyGroup>
</Project>


0
投票

抱歉,如果它很明显,但我更新了代码,就像我在 c\Sites 中显示的代码一样,但我仍然遇到同样的问题

-v“C:\站点:/ContainerFolder:ro”< DockerfileRunArguments>

© www.soinside.com 2019 - 2024. All rights reserved.