Skip to content

Instantly share code, notes, and snippets.

@Pvlerick
Created December 24, 2018 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pvlerick/0bc6c762733d40bad7138b1a4d9dc3a2 to your computer and use it in GitHub Desktop.
Save Pvlerick/0bc6c762733d40bad7138b1a4d9dc3a2 to your computer and use it in GitHub Desktop.
DockerClientExtensions
using System;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Docker.DotNet;
using Docker.DotNet.Models;
public static class DockerClientExtensions
{
public static async Task WaitForLogMessage(this DockerClient client, string containerId, string pattern, TimeSpan readDelay)
{
var buffer = new byte[1024];
for (int i = 0; i < 120; i++)
{
var stream = await client.Containers.GetContainerLogsAsync(containerId, new ContainerLogsParameters { ShowStdout = true, ShowStderr = true });
var count = await stream.ReadAsync(buffer);
var logs = System.Text.Encoding.UTF8.GetString(buffer, 0, count);
if (count > 0 && Regex.IsMatch(logs, pattern))
break;
await Task.Delay(readDelay);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment