Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ public DockerClient(@Nonnull Launcher launcher, @CheckForNull Node node, @CheckF
*/
public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNull String args, @CheckForNull String workdir, @Nonnull Map<String, String> volumes, @Nonnull Collection<String> volumesFromContainers, @Nonnull EnvVars containerEnv, @Nonnull String user, @Nonnull String... command) throws IOException, InterruptedException {
ArgumentListBuilder argb = new ArgumentListBuilder();
boolean iswin = !launcher.isUnix();

argb.add("run", "-t", "-d");
if (!iswin) {
argb.add("-u", user);
}

argb.add("run", "-t", "-d", "-u", user);
if (args != null) {
argb.addTokenized(args);
}
Expand All @@ -115,7 +120,7 @@ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNu
argb.add("-w", workdir);
}
for (Map.Entry<String, String> volume : volumes.entrySet()) {
argb.add("-v", volume.getKey() + ":" + volume.getValue() + ":rw,z");
argb.add("-v", volume.getKey() + ":" + volume.getValue() + (iswin ? ":rw" : ":rw,z"));
}
for (String containerId : volumesFromContainers) {
argb.add("--volumes-from", containerId);
Expand All @@ -135,7 +140,13 @@ public String run(@Nonnull EnvVars launchEnv, @Nonnull String image, @CheckForNu
}

public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String containerId) throws IOException, InterruptedException {
LaunchResult result = launch(launchEnv, false, "top", containerId, "-eo", "pid,comm");
LaunchResult result;
boolean iswin = !launcher.isUnix();
if (iswin) {
result = launch(launchEnv, false, "top", containerId);
} else {
result = launch(launchEnv, false, "top", containerId, "-eo", "pid,comm");
}
if (result.getStatus() != 0) {
throw new IOException(String.format("Failed to run top '%s'. Error: %s", containerId, result.getErr()));
}
Expand All @@ -149,8 +160,12 @@ public List<String> listProcess(@Nonnull EnvVars launchEnv, @Nonnull String cont
if (stringTokenizer.countTokens() < 2) {
throw new IOException("Unexpected `docker top` output : "+line);
}
stringTokenizer.nextToken(); // PID
processes.add(stringTokenizer.nextToken()); // COMMAND
// Somehow docker top only displays the process list reliably when using 'pid,comm' so ignore pid if on linux
if (!iswin) {
stringTokenizer.nextToken();
}
// Windows containers are started without the .exe suffix to cat but top returns cat.exe
processes.add(iswin ? stringTokenizer.nextToken().replace(".exe","") : stringTokenizer.nextToken()); // COMMAND
}
}
return processes;
Expand Down