WSL2 Docker Linux 卷权限问题

WSL2 Docker Linux Permission Issue with Volumes

我正在使用 Docker 构建 Jekyll 网站。我在 Debian 中使用 Windows 10 和 WSL2。 如果我 运行 在我的 Windows 环境

中使用来自 Powershell 的以下内容
docker run --rm --label=jekyll --volume=C:/_projects/site/theme:/srv/jekyll -it -p 4000:4000 jekyll/jekyll jekyll serve

如果尝试 运行 从我的 Debian shell 通过 WSL2

docker run --rm --label=jekyll --volume=/mnt/c/_projects/site/theme:/srv/jekyll -it -p 4000:4000 jekyll/jekyll jekyll serve

然后我得到一个错误:-

Configuration file: /srv/jekyll/_config.yml
            Source: /srv/jekyll
       Destination: /srv/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
jekyll 3.8.5 | Error:  Operation not permitted @ apply2files - /srv/jekyll/_site/assets/css/font-awesome.css
Traceback (most recent call last):
        25: from /usr/local/bundle/bin/jekyll:29:in `<main>'
        24: from /usr/local/bundle/bin/jekyll:29:in `load'
        23: from /usr/gem/gems/jekyll-3.8.5/exe/jekyll:15:in `<top (required)>'
        22: from /usr/gem/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
        21: from /usr/gem/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
        20: from /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
        19: from /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
        18: from /usr/gem/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
        17: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:75:in `block (2 levels) in init_with_program'
        16: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `start'
        15: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `each'
        14: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/serve.rb:93:in `block in start'
        13: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:36:in `process'
        12: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/commands/build.rb:65:in `build'
        11: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/command.rb:28:in `process_site'
        10: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:73:in `process'
         9: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:208:in `write'
         8: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:330:in `each_site_file'
         7: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:330:in `each'
         6: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:331:in `block in each_site_file'
         5: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:331:in `each'
         4: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:332:in `block (2 levels) in each_site_file'
         3: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/site.rb:209:in `block in write'
         2: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/static_file.rb:105:in `write'
         1: from /usr/gem/gems/jekyll-3.8.5/lib/jekyll/static_file.rb:163:in `copy_file'
/usr/gem/gems/jekyll-3.8.5/lib/jekyll/static_file.rb:163:in `utime': Operation not permitted @ apply2files - /srv/jekyll/_site/assets/css/font-awesome.css (Errno::EPERM)

我的直觉是我遇到了 Linux 文件权限问题,但我不知道如何解决它,或者我的假设是否正确。

我不得不编辑 wsl.conf

sudo nano /etc/wsl.conf

# Now make it look like this and save the file when you're done:
[automount]
root = /
options = "metadata"

https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly#ensure-volume-mounts-work

中所述

感谢@NotTheDr01ds