How to call docker start from C # application
I have a WPF application while file processing requires using a docker process. The docker container is built on a box, currently after processing the file with a WPF app, the user has to start a command prompt and type
docker run --it --rm -v folderdedirect process parameters_including_filePath
for further processing.
I want to include this in a WPF application. I would presumably use system.diagnostics.process
with cmd.exe
? I have looked at Docker.dotnet
, but could not for a lifetime figure out how it is supposed to run a local container.
+5
source to share
1 answer
This is how I ended up doing it, but maybe there is a better way.
var processInfo = new ProcessStartInfo("docker", $"run -it --rm blahblahblah");
processInfo.CreateNoWindow = true;
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
int exitCode;
using (var process = new Process())
{
process.StartInfo = processInfo;
process.OutputDataReceived += new DataReceivedEventHandler(logOrWhatever());
process.ErrorDataReceived += new DataReceivedEventHandler(logOrWhatever());
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit(1200000);
if (!process.HasExited)
{
process.Kill();
}
exitCode = process.ExitCode;
process.Close();
}
0
source to share