public static Container findContainerByIdOrByName ( String name , DockerClient dockerClient ) { Container result = null ; List < Container > containers = dockerClient . listContainersCmd ( ) . withShowAll ( true ) . exec ( ) ; for ( Container container : containers ) { List < String > names = Arrays . asList ( container . getNames ( ) ) ; // Docker containers are prefixed with '/'. // At least, those we created, since their parent is the Docker daemon. if ( container . getId ( ) . equals ( name ) || names . contains ( "/" + name ) ) { result = container ; break ; } } return result ; }
Finds a container by ID or by name .