Skip to content

Commit 80c6fd9

Browse files
authored
Merge pull request jenkinsci#69 from jglick/DockerClient.getVolumes
DockerClient.getVolumes fix
2 parents 5b09129 + 4f99c3c commit 80c6fd9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public String whoAmI() throws IOException, InterruptedException {
293293
*
294294
* @return an optional string containing the <strong>container id</strong>, or <strong>absent</strong> if
295295
* it isn't containerized.
296+
* @see <a href="http://stackoverflow.com/a/25729598/12916">Discussion</a>
296297
*/
297298
public Optional<String> getContainerIdIfContainerized() throws IOException, InterruptedException {
298299
final Pattern pattern = Pattern.compile(CGROUP_MATCHER_PATTERN);
@@ -321,15 +322,16 @@ public ContainerRecord getContainerRecord(@Nonnull EnvVars launchEnv, String con
321322
}
322323

323324
/**
324-
* Inspect the volumes of a docker image/container.
325+
* Inspect the mounts of a container.
326+
* These might have been declared {@code VOLUME}s, or mounts defined via {@code --volume}.
325327
* @param launchEnv Docker client launch environment.
326-
* @param objectId The image/container ID.
327-
* @return a list of volumes of the docker image/container.
328+
* @param containerID The container ID.
329+
* @return a list of filesystem paths inside the container
328330
* @throws IOException Execution error. Also fails if cannot retrieve the requested field from the request
329331
* @throws InterruptedException Interrupted
330332
*/
331-
public List<String> getVolumes(@Nonnull EnvVars launchEnv, String objectId) throws IOException, InterruptedException {
332-
LaunchResult result = launch(launchEnv, true, "inspect", "-f", "{{range $index, $element := .Config.Volumes}}{{$index}}\n{{end}}", objectId);
333+
public List<String> getVolumes(@Nonnull EnvVars launchEnv, String containerID) throws IOException, InterruptedException {
334+
LaunchResult result = launch(launchEnv, true, "inspect", "-f", "{{range .Mounts}}{{.Destination}}\n{{end}}", containerID);
333335
if (result.getStatus() != 0) {
334336
return Collections.emptyList();
335337
}

0 commit comments

Comments
 (0)