@Override
  protected void execute(final DockerClient docker)
      throws MojoExecutionException, GitAPIException, IOException, DockerException,
             InterruptedException {

    if (weShouldSkipDockerBuild()) {
      getLog().info("Skipping docker build");
      return;
    }

    // Put the list of exposed ports into a TreeSet which will remove duplicates and keep them
    // in a sorted order. This is useful when we merge with ports defined in the profile.
    exposesSet = Sets.newTreeSet(exposes);
    if (runs != null) {
      runList = Lists.newArrayList(runs);
    }
    expressionEvaluator = new PluginParameterExpressionEvaluator(session, execution);

    final Git git = new Git();
    final String commitId = git.isRepository() ? git.getCommitId() : null;

    if (commitId == null) {
      final String errorMessage =
          "Not a git repository, cannot get commit ID. Make sure git repository is initialized.";
      if (useGitCommitId || ((imageName != null) && imageName.contains("${gitShortCommitId}"))) {
        throw new MojoExecutionException(errorMessage);
      } else {
        getLog().debug(errorMessage);
      }
    } else {
      // Put the git commit id in the project properties. Image names may contain
      // ${gitShortCommitId} in which case we want to fill in the actual value using the
      // expression evaluator. We will do that once here for image names loaded from the pom,
      // and again in the loadProfile method when we load values from the profile.
      mavenProject.getProperties().put("gitShortCommitId", commitId);
      if (imageName != null) {
        imageName = expand(imageName);
      }
      if (baseImage != null) {
        baseImage = expand(baseImage);
      }
    }

    loadProfile();
    validateParameters();

    final String[] repoTag = parseImageName(imageName);
    final String repo = repoTag[0];
    final String tag = repoTag[1];

    if (useGitCommitId) {
      if (tag != null) {
        getLog().warn("Ignoring useGitCommitId flag because tag is explicitly set in image name ");
      } else if (commitId == null) {
        throw new MojoExecutionException(
            "Cannot tag with git commit ID because directory not a git repo");
      } else {
        imageName = repo + ":" + commitId;
      }
    }
    mavenProject.getProperties().put("imageName", imageName);

    final String destination = getDestination();
    if (dockerDirectory == null) {
      final List<String> copiedPaths = copyResources(destination);
      createDockerFile(destination, copiedPaths);
    } else {
      final Resource resource = new Resource();
      resource.setDirectory(dockerDirectory);
      resources.add(resource);
      copyResources(destination);
    }

    buildImage(docker, destination, buildParams());
    tagImage(docker, forceTags);

    final DockerBuildInformation buildInfo = new DockerBuildInformation(imageName, getLog());

    if ("docker".equals(mavenProject.getPackaging())) {
      final File imageArtifact = createImageArtifact(mavenProject.getArtifact(), buildInfo);
      mavenProject.getArtifact().setFile(imageArtifact);
    }

    // Push specific tags specified in pom rather than all images
    if (pushImageTag) {
      pushImageTag(docker, imageName, imageTags, getLog(), isSkipDockerPush());
    }

    if (pushImage) {
      pushImage(docker, imageName, imageTags, getLog(), buildInfo, getRetryPushCount(),
          getRetryPushTimeout(), isSkipDockerPush());
    }

    if (saveImageToTarArchive != null) {
        saveImage(docker, imageName, Paths.get(saveImageToTarArchive), getLog());
    }

    // Write image info file
    writeImageInfoFile(buildInfo, tagInfoFile);
  }
Set the networking mode for the RUN instructions during build
src/main/java/com/spotify/docker/BuildMojo.java