public void addShutdownHookForStoppingContainers ( final boolean keepContainer , final boolean removeVolumes , final boolean removeCustomNetworks ) { Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { @ Override public void run ( ) { try { stopStartedContainers ( keepContainer , removeVolumes , removeCustomNetworks , null ) ; } catch ( DockerAccessException | ExecException e ) { log . error ( "Error while stopping containers: %s" , e . getMessage ( ) ) ; } } } ) ; }
Add a shutdown hook in order to stop all registered containers