public void stop ( ) throws InterruptedException { // Tell docker to stop or eventually kill the container final String container = containerId . or ( containerName ) ; // Interrupt the thread blocking on waitContainer stopAsync ( ) . awaitTerminated ( ) ; if ( System . getenv ( "CONTAINER_STATS" ) != null ) { try { log . info ( "container {} stats: {}" , containerName , docker . stats ( containerName ) ) ; } catch ( DockerException e ) { log . warn ( "Could not log container stats. Exception was {}" , e ) ; } } try { docker . stopContainer ( container , secondsToWaitBeforeKill ) ; } catch ( DockerException e ) { if ( ( e instanceof ContainerNotFoundException ) && ! containerId . isPresent ( ) ) { // we tried to stop the container by name but no container of the given name existed. // this isn't surprising or exceptional, just means the container wasn't started yet. } else { log . warn ( "Stopping container {} failed" , container , e ) ; } } }
Stops this container .