将 .net exe 放入 Docker 容器中

3

我试图将一个.net控制台应用程序移植到docker容器中。该应用程序尝试调用ffmpeg.exe,但我遇到了错误?是否可能在该容器中无法运行exe文件?

static void encoder(string inputFile, string outputFolder, string outputFileName)
{
    if (!Directory.Exists(outputFolder))
    {
        Directory.CreateDirectory(outputFolder);
    }

    var GetDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

    // Part 1: use ProcessStartInfo class.
    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.CreateNoWindow = false;
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardInput = true;
    startInfo.FileName = GetDirectory + @"/ffmpeg.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;

    // Part 2: set arguments.
    startInfo.Arguments = "-i " + inputFile + " -q:a 8 -filter:a loudnorm " + outputFolder + outputFileName;

    // Part 3: start with the info we specified.
    // ... Call WaitForExit.
    using (Process exeProcess = Process.Start(startInfo))
    {
        exeProcess.StandardInput.WriteLine("y");
        exeProcess.WaitForExit();
    }

}

错误

OPUS-Encoder System.ComponentModel.Win32Exception (8): An error occurred trying to start process '/App/ffmpeg.exe' with working directory '/App'. Exec format error
   at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at System.Diagnostics.Process.Start()
   at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
   at Program.<<Main>$>g__encoder|0_0(String inputFile, String outputFolder, String outputFileName) in /App/Program.cs:line 77
   at Program.<Main>$(String[] args) in /App/Program.cs:line 34

谢谢


2
你使用的是 Windows 还是 Linux 容器? - mamen
3
错误提示关于 ffpmeg.exeExec format error 错误是 Linux 错误。你不能在 Linux 上运行 Windows 二进制文件,你需要发布并调用 Linux 二进制文件。在 Linux 上,你可以通过 apt-get 安装 ffmpeg。该文件不会有 .exe 扩展名。 - Panagiotis Kanavos
1个回答

2

看起来你的 Docker 容器正在运行 Linux,但可执行文件是 Windows PE。

如果你的容器正在运行 Linux,你需要 Linux 二进制文件而不是 Windows 的 ".exe" 文件。 你可以在这里获取一个 链接

调用 API 的方式将保持不变。

如果你想支持 Linux 和 Windows,你需要根据当前操作系统更改路径参数。 这里有一个关于如何在运行时进行更改的 问题


调用是一样的,只是结尾没有.exe吗?我使用Linux容器! - newby567
API是相同的,只有路径参数会不同。 - Kliment Nechaev
@newby567,不仅如此,您还需要在容器中安装Linux版本的FFmpeg,并使用适当的命令运行它。 - Guru Stron

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接