Docker 保存 gzip "Error response from daemon: invalid reference format"仅在 C# 中使用 Process.start(),从 CMD



我正在尝试在Windows操作系统上导出容器映像。

我有一个示例命令:
docker save myimatetest:latest > C:temp.tar.gz

,当我通过命令行执行它时,它正在工作,但是当我试图使用c#的进程类调用相同的命令时,它会崩溃:

来自守护进程的错误响应:无效的引用格式

这是我使用的代码:

Process process = new Process();
StringBuilder outputBuilder = new StringBuilder();
StringBuilder errorBuilder = new StringBuilder();
string workDir = Path.GetDirectoryName(@"F:mydirdockerfilelocation");
process.StartInfo.WorkingDirectory = workDir;
process.StartInfo.FileName = "docker";
process.StartInfo.Arguments = @"save myimatetest:latest > C:temp.tar.gz";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
outputBuilder.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
errorBuilder.AppendLine(e.Data);
}
};

process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
process.ExitCode.Dump();
outputBuilder.Dump();
errorBuilder.Dump();

你知道是什么原因引起的吗?

此处不能使用标准输出重定向,但需要使用-o选项指定输出文件名

process.StartInfo.Arguments = @"save -o C:temp.tar myimatetest:latest";

相关内容

最新更新