DockerCommand { public void killContainer(String containerId) throws IOException, TimeoutException, InterruptedException { checkArgument(containerId != null); checkArgument( CONTAINER_ID_PATTERN.matcher(containerId).matches(), "Container ID must be a 64-character hexadecimal string"); runShortCommand(Arrays.asList(dockerExecutable, "kill", containerId)); } private  DockerCommand(String dockerExecutable, Duration commandTimeout); static DockerCommand getDefault(); String runImage(String imageTag, List<String> dockerOpts, List<String> args); boolean isContainerRunning(String containerId); String getContainerLogs(String containerId); void killContainer(String containerId); void removeContainer(String containerId);  }
@Test public void killContainer() throws Exception { DockerCommand docker = DockerCommand.getDefault(); String container = docker.runImage( "debian", ImmutableList.of(), ImmutableList.of("/bin/bash", "-c", "sleep 60")); Stopwatch stopwatch = Stopwatch.createStarted(); assertThat("Container should be running.", docker.isContainerRunning(container), is(true)); docker.killContainer(container); long elapsedSec = stopwatch.elapsed(TimeUnit.SECONDS); assertThat( "Container termination should complete before image self-exits", elapsedSec, is(lessThan(60L))); assertThat("Container should be terminated.", docker.isContainerRunning(container), is(false)); }