Skip to content

Commit

Permalink
Merge pull request #166 from samwright/fix/health-status-on-windows
Browse files Browse the repository at this point in the history
Fix docker health check to work on Windows.
  • Loading branch information
alicederyn authored Mar 1, 2017
2 parents 19d88e6 + 3dae325 commit caba355
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -41,6 +43,7 @@ public class Docker {
+ "{{if eq .State.Health.Status \"healthy\"}}HEALTHY"
+ "{{else}}UNHEALTHY{{end}}"
+ "{{else}}HEALTHY{{end}}";
private static final String HEALTH_STATUS_FORMAT_WINDOWS = HEALTH_STATUS_FORMAT.replaceAll("\"", "`\"");

public static Version version() throws IOException, InterruptedException {
Command command = new Command(
Expand All @@ -58,8 +61,8 @@ public Docker(DockerExecutable rawExecutable) {
}

public State state(String containerId) throws IOException, InterruptedException {
String stateString = command.execute(
Command.throwingOnError(), "inspect", HEALTH_STATUS_FORMAT, containerId);
String formatString = SystemUtils.IS_OS_WINDOWS ? HEALTH_STATUS_FORMAT_WINDOWS : HEALTH_STATUS_FORMAT;
String stateString = command.execute(Command.throwingOnError(), "inspect", formatString, containerId);
return State.valueOf(stateString);
}

Expand Down

0 comments on commit caba355

Please sign in to comment.