private Task<ImageWatcher> defaultContainerRestartTask() {
        return watcher -> {
            // Stop old one
            ImageConfiguration imageConfig = watcher.getImageConfiguration();
            PortMapping mappedPorts = runService.createPortMapping(imageConfig.getRunConfiguration(), watcher.getWatchContext().getMojoParameters().getProject().getProperties());
            String id = watcher.getContainerId();

            String optionalPreStop = getPreStopCommand(imageConfig);
            if (optionalPreStop != null) {
                runService.execInContainer(id, optionalPreStop, watcher.getImageConfiguration());
            }
            runService.stopPreviouslyStartedContainer(id, false, false);

            // Start new one
            StartContainerExecutor helper = new StartContainerExecutor.Builder()
                    .dispatcher(watcher.watchContext.dispatcher)
                    .follow(watcher.watchContext.follow)
                    .log(log)
                    .portMapping(mappedPorts)
                    .gavLabel(watcher.watchContext.getGavLabel())
                    .projectProperties(watcher.watchContext.mojoParameters.getProject().getProperties())
                    .basedir(watcher.watchContext.mojoParameters.getProject().getBasedir())
                    .imageConfig(imageConfig)
                    .serviceHub(watcher.watchContext.hub)
                    .logOutputSpecFactory(watcher.watchContext.serviceHubFactory.getLogOutputSpecFactory())
                    .showLogs(watcher.watchContext.showLogs)
                    .containerNamePattern(watcher.watchContext.containerNamePattern)
                    .buildTimestamp(watcher.watchContext.buildTimestamp)
                    .build();

            String containerId = helper.startContainer();
            watcher.setContainerId(containerId);
        };
    }
Watch service for monitoring changes and restarting containers
src/main/java/io/fabric8/maven/docker/service/WatchService.java