private void updateMappedPortsAndAddresses(String containerId, PortMapping mappedPorts) throws DockerAccessException {
        RetryPolicy<Void> retryPolicy = new RetryPolicy<Void>()
                .withMaxAttempts(20)
                .withBackoff(10, 100, ChronoUnit.MILLIS)
                .handle(PortBindingException.class)
                .onFailedAttempt(f -> log.debug("Failed to update mapped ports for container %s (attempt %d), retrying",
                        containerId, f.getAttemptCount()))
                .onRetriesExceeded(f -> log.warn("Failed to update mapped ports for container %s after %d retries",
                        containerId, f.getAttemptCount()));

        Failsafe.with(retryPolicy).run(() -> {
            Container container = queryService.getMandatoryContainer(containerId);
            if (container.isRunning()) {
                mappedPorts.updateProperties(container.getPortBindings());
            } else {
                log.warn("Container %s is not running anymore, can not extract dynamic ports", containerId);
            }
        });
    }
Add a shutdown hook in order to stop all registered containers
src/main/java/io/fabric8/maven/docker/service/RunService.java