Source:
public void startContainerWithVolumes() throws DockerException { Volume volume1 = new Volume("/opt/webapp1"); Volume volume2 = new Volume("/opt/webapp2"); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume1, volume2) .withCmd("true").withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2)) .exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(), contains("/opt/webapp1", "/opt/webapp2")); dockerClient.startContainerCmd(container.getId()).exec(); dockerClient.waitContainerCmd(container.getId()).exec(new WaitContainerResultCallback()).awaitStatusCode(); inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertContainerHasVolumes(inspectContainerResponse, volume1, volume2); assertEquals(inspectContainerResponse.getMounts().size(), 2); assertEquals(inspectContainerResponse.getMounts().get(0).getDestination(), volume1); assertEquals(inspectContainerResponse.getMounts().get(0).getMode(), "ro"); assertEquals(inspectContainerResponse.getMounts().get(0).getRW(), Boolean.FALSE); assertEquals(inspectContainerResponse.getMounts().get(1).getDestination(), volume2); assertEquals(inspectContainerResponse.getMounts().get(1).getMode(), "rw"); assertEquals(inspectContainerResponse.getMounts().get(1).getRW(), Boolean.TRUE); }

Target:
public void startContainerWithVolumes() throws DockerException { Volume volume1 = new Volume("/opt/webapp1"); Volume volume2 = new Volume("/opt/webapp2"); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withVolumes(volume1, volume2) .withCmd("true").withBinds(new Bind("/src/webapp1", volume1, ro), new Bind("/src/webapp2", volume2)) .exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertThat(inspectContainerResponse.getConfig().getVolumes().keySet(), contains("/opt/webapp1", "/opt/webapp2")); dockerClient.startContainerCmd(container.getId()).exec(); dockerClient.waitContainerCmd(container.getId()).exec(new WaitContainerResultCallback()).awaitStatusCode(); inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertThat(inspectContainerResponse, mountedVolumes(containsInAnyOrder(volume1, volume2))); assertThat(inspectContainerResponse.getMounts().size(), equalTo(2)); assertThat(inspectContainerResponse.getMounts().get(0).getDestination(), equalTo(volume1)); assertThat(inspectContainerResponse.getMounts().get(0).getMode(), equalTo("ro")); assertThat(inspectContainerResponse.getMounts().get(0).getRW(), equalTo(Boolean.FALSE)); assertThat(inspectContainerResponse.getMounts().get(1).getDestination(), equalTo(volume2)); assertThat(inspectContainerResponse.getMounts().get(1).getMode(), equalTo("rw")); assertThat(inspectContainerResponse.getMounts().get(1).getRW(), equalTo(Boolean.TRUE)); }