Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# dotnet核心文件.移动问题_C#_Docker_.net Core - Fatal编程技术网

C# dotnet核心文件.移动问题

C# dotnet核心文件.移动问题,c#,docker,.net-core,C#,Docker,.net Core,我的Dockerfile是这个 FROM mcr.microsoft.com/dotnet/core/runtime:3.0 COPY publish/ app/ RUN mkdir -p /in RUN mkdir -p /tmp ENTRYPOINT ["dotnet", "app/Watcher.dll"] 我用这个命令建立图像 docker build -t watcher/sl_user_test:1.1 . 那么,我的码头工人是这样写的 watcher.sl_user_tes

我的Dockerfile是这个

FROM mcr.microsoft.com/dotnet/core/runtime:3.0

COPY publish/ app/
RUN mkdir -p /in
RUN mkdir -p /tmp

ENTRYPOINT ["dotnet", "app/Watcher.dll"]
我用这个命令建立图像

docker build -t watcher/sl_user_test:1.1 .
那么,我的码头工人是这样写的

watcher.sl_user_test:
  image: watcher/sl_user_test:1.1
  container_name: watcher_sl_user_test
  build: .
  restart: always
  volumes:
    - /var/storage/in:/in:z
    - /var/storage/tmp:/tmp:z
在我的dotnetcore应用程序中,我在/In文件夹中得到一个文件,并将其移动到/tmp/aaa 这是什么代码

string destination = $"/tmp/{Guid.NewGuid()}/git.zip";
new FileInfo(destination).Directory.Create();
File.Move("/in/git.zip", destination, true);
问题是,这个命令复制文件,但不移动它,为什么?
如果我进入容器内部,我可以从bash执行mv,并且它可以工作

,因为您正在路径中创建一个新的GUID,所以该目录保证不存在。因此,
File.Move
将抛出一个
DirectoryNotFoundException

在移动文件之前创建它

var tmpDir = $"/tmp/{Guid.NewGuid()}";
Directory.CreateDirectory(tmpDir);
File.Move("/in/git.zip", $"{tmpDir}/git.zip", true);
假设您正在这样做,如果
File.Move
方法只是复制而不是移动,那么很可能原始文件正在使用中。摘自(备注部分):

如果尝试跨磁盘卷移动文件,并且该文件正在使用中,则会将该文件复制到目标,但不会从源中删除该文件


问题是我试图将文件从一个卷移动到另一个卷。 如果您在GoLang尝试此代码,您将收到此错误

"rename /dir1/test.txt /dir2/test.txt: invalid cross-device link"
因此,解决方案是

  • 编写自己的FileMove函数(使用复制和删除源)
  • 只使用一个卷
所以,在我的情况下,从这个

volumes:
  - /var/storage/in:/in:z
  - /var/storage/tmp:/tmp:z
我会这么做的

volumes:
  - /var/storage/data/:/data:z

在/data中有“in”和“tmp”文件夹

您可以使用文件吗?是否删除原始文件?File.GetAttributes返回什么?同一个程序可以读取移动文件的源吗?file.Delete worksFile.GetAttributes说“Normal”这是一个很好的提示,但我使用此函数来验证文件是否正在使用,并且如果我直接运行应用程序(不带docker)文件,则始终不会锁定。移动可以工作