ASP.NET Core + Docker + 公开 wwwroot

Ric*_*res 5 docker asp.net-core

我正在尝试使用 Docker 运行 ASP.NET Core 应用程序,并且希望将外部 wwwroot 文件夹公开给容器,以便当我从外部对其进行更改时,它们会自动可供我的应用程序使用。使用卷这可能吗?

Tar*_*ani 4

对的,这是可能的。如果您使用 docker run 那么您应该执行以下操作

docker run -v /path/on/host:/wwwroot/path/in/container <image>
Run Code Online (Sandbox Code Playgroud)

如果您使用docker-compose,则应将以下内容添加到服务中

version: "3"
services:
  myapp:
    build: .
    volumes:
      - /path/on/host:/wwwroot/path/in/container
Run Code Online (Sandbox Code Playgroud)

如果您在 Windows 版 Docker 上使用它,那么您可能需要进行一些路径转换,例如

/c/path/on/host:/wwwroot/path/in/container
Run Code Online (Sandbox Code Playgroud)