Skip to content

Commit b01cd35

Browse files
authored
Merge pull request #67 from opencb/TASK-2315
TASK-2315 Fix docker command lines executions when using the DockerUtils
2 parents 647778a + 1b2f296 commit b01cd35

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ private static List<String> getPaths(String entryPoint) {
141141
public static String run(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
142142
AbstractMap.SimpleEntry<String, String> outputBinding, String cmdParams,
143143
Map<String, String> dockerParams) throws IOException {
144+
checkDockerDaemonAlive();
145+
144146
String commandLine = buildCommandLine(image, inputBindings, outputBinding, cmdParams, dockerParams);
145147

146148
LOGGER.info("Run docker command line");
@@ -154,4 +156,26 @@ public static String run(String image, List<AbstractMap.SimpleEntry<String, Stri
154156

155157
return commandLine;
156158
}
159+
160+
public static void checkDockerDaemonAlive() throws IOException {
161+
int maxAttempts = 12;
162+
for (int i = 0; i < maxAttempts; i++) {
163+
Command command = new Command("docker stats --no-stream");
164+
command.run();
165+
if (command.getExitValue() == 0) {
166+
// Docker is alive
167+
if (i != 0) {
168+
LOGGER.info("Docker daemon up and running!");
169+
}
170+
return;
171+
}
172+
LOGGER.info("Waiting for docker to start... (sleep 5s) [" + i + "/" + maxAttempts + "]");
173+
try {
174+
Thread.sleep(5000);
175+
} catch (InterruptedException e) {
176+
throw new IOException(e);
177+
}
178+
}
179+
throw new IOException("Docker daemon is not available on this node!");
180+
}
157181
}

0 commit comments

Comments
 (0)