MSYS2无法删除Windows docker卷中的文件

MSYS2无法删除Windows docker卷中的文件,windows,docker,msys2,Windows,Docker,Msys2,我遇到一个问题,在docker中运行的MSYS2可以在已装入的卷中创建和修改文件,但不能删除它们。这可以通过显式删除的命令(如rm a.txt)或隐式删除的命令(如sed-i's/foo/bar/'b.txt)观察到(b.txt应就地编辑,并从输出(1)中读取、删除和重新创建)。可以使用等效的DOS命令删除相同的文件,例如dela.txt 使用以下Dockerfile: # Altered from https://github.com/StefanScherer/dockerfiles-win

我遇到一个问题,在docker中运行的MSYS2可以在已装入的卷中创建和修改文件,但不能删除它们。这可以通过显式删除的命令(如
rm a.txt
)或隐式删除的命令(如
sed-i's/foo/bar/'b.txt
)观察到(b.txt应就地编辑,并从输出(1)中读取、删除和重新创建)。可以使用等效的DOS命令删除相同的文件,例如
dela.txt

使用以下Dockerfile:

# Altered from https://github.com/StefanScherer/dockerfiles-windows/blob/main/msys2/Dockerfile
FROM mcr.microsoft.com/windows/servercore:20H2

RUN powershell -Command \
    $ProgressPreference = 'SilentlyContinue' ; \
    Write-Output 'Downloading msys2' ; \
    curl.exe -o msys2.tar.xy http://repo.msys2.org/distrib/msys2-x86_64-latest.tar.xz ; \
    Install-Package -Scope CurrentUser -Force 7Zip4Powershell ; \
    Write-Output 'Extracting tar.xz' ; \
    Expand-7zip msys2.tar.xy . ; \
    Write-Output 'Extracting tar' ; \
    Expand-7zip msys2.tar C:/ ; \
    Write-Output 'Done'

RUN powershell -Command \
    setx /M PATH $('C:\msys64\mingw64\bin;C:\msys64\usr\bin;C:\msys64\mingw32\bin;' + $Env:PATH)
使用以下内容构建并启动容器:

docker pull mcr.microsoft.com/windows/servercore:20H2
docker build -t docker-msys .
mkdir local
docker run -ti -v "$(pwd)/local:C:/local" docker-msys cmd.exe
使用容器中的MSYS2命令,让我们使用以下命令操作文件:

touch a.txt
cp a.txt b.txt
rm a.txt
rm -f b.txt
ls *.txt
如果从未装入的目录启动,则会观察到以下情况:

C:\>touch a.txt
C:\>cp a.txt b.txt
C:\>rm a.txt
C:\>rm -f b.txt
C:\>ls *.txt
ls: cannot access '*.txt': No such file or directory
cd C:\local
C:\local>touch a.txt
C:\local>cp a.txt b.txt
C:\local>rm a.txt
rm: cannot remove 'a.txt': Invalid argument
C:\local>rm -f b.txt
C:\local>ls *.txt
a.txt  b.txt
两个文件都已按预期删除

如果从装入的目录(此处为
C:\local
)启动,则会观察到以下情况:

C:\>touch a.txt
C:\>cp a.txt b.txt
C:\>rm a.txt
C:\>rm -f b.txt
C:\>ls *.txt
ls: cannot access '*.txt': No such file or directory
cd C:\local
C:\local>touch a.txt
C:\local>cp a.txt b.txt
C:\local>rm a.txt
rm: cannot remove 'a.txt': Invalid argument
C:\local>rm -f b.txt
C:\local>ls *.txt
a.txt  b.txt
这两个文件仍然存在

其他MSYS命令在装载的目录中将有意外行为:

C:\local>sed -i 's/foo/bar/' b.txt
sed: cannot remove ./sed7E6QmG: Invalid argument
可以使用等效的dos命令从装入的目录中删除文件:

C:\local>del /Q *

C:\local>dir
 Volume in drive C has no label.
 Volume Serial Number is 541F-A7C7

 Directory of C:\local

11/26/2020  04:05 PM    <DIR>          .
11/26/2020  04:05 PM    <DIR>          ..
               0 File(s)              0 bytes
               2 Dir(s)  48,827,674,624 bytes free
该问题似乎与我的Dockerfile无关。我可以用一个容器从中复制它

进入容器后,执行
set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;C:\msys64\mingw32\bin;%路径%

最后,与在docker中安装MSYS2不同,在容器中安装MSYS2的目录也会产生同样的情况

我有什么遗漏吗

详情:

  • Windows 10 Pro,20H2,19042.746
  • Docker Desktop 3.1.0(51484)
  • MSYS2()2020-07-03 19:34
(1) 我谦卑的解释

添加
--isolation=process
修复了它<代码>rm
对我来说不再失败

docker pull mcr.microsoft.com/windows/servercore:20H2
docker build -t docker-msys .
mkdir local
docker run --rm -ti --isolation=process -v "$(pwd)/local:C:/local" docker-msys cmd.exe
重新运行前面的命令会产生:

C:\>cd local
C:\local>touch a.txt
C:\local>cp a.txt b.txt
C:\local>rm a.txt
C:\local>rm -f b.txt
C:\local>ls *.txt
ls: cannot access '*.txt': No such file or directory