$ show fabric8io/docker-maven-plugin
This is a mature Maven plugin (io.fabric8:docker-maven-plugin) that integrates Docker container lifecycle management into Maven builds. It enables building Docker images from Dockerfiles, Maven assemblies, or Jib; pushing images to registries; running containers for integration tests; and managing volumes, networks, and logs. The plugin is widely used in Java/Spring Boot projects for containerized testing and deployment. Architecturally, the plugin follows a layered design: Maven Mojo classes (e.g., BuildMojo, StartMojo, StopMojo) serve as entry points, delegating to a service layer (ServiceHub, BuildService, RunService, RegistryService) that orchestrates Docker operations. The access layer (DockerAccess interface, implemented by DockerAccessWithHcClient) communicates with the Docker daemon via HTTP over Unix sockets, Windows named pipes, or TCP. Configuration is resolved from Maven POM XML, Maven properties, Docker Compose files, or external handlers, with a flexible property merging system. Key data flows include: (1) image build: resolve configuration → create build context (assembly or Dockerfile) → send to Docker daemon → tag and optionally push; (2) container lifecycle: resolve run config → create container → start with wait conditions → track for shutdown; (3) authentication: chain of providers (system properties, Maven settings, Docker config.json, credential helpers, AWS ECR, OpenShift) to obtain registry credentials. The plugin also supports BuildX for multi-architecture images and a watch mode for live-reload during development. External dependencies include the Docker Engine API, Apache HttpClient 4.x, Google Gson, SnakeYAML, Jib Core, and jnr-unixsocket. The codebase is well-tested with over 200 unit tests and integration tests running against multiple Docker versions on Linux, macOS, and Windows.
The LLM identified 5 files worth highlighting for reuse:
Implements a multi-source authentication chain for Docker registries. Supports system properties, Maven settings, Docker config.json, credential helpers (docker-credential-*), AWS ECR (via environment, IAM roles, ECS task roles), and OpenShift kubeconfig. Each source is tried in order until credentials are found. The design is cleanly extensible: adding a new auth source requires implementing a single method. This component is self-contained (no internal imports beyond standard Java and a few utility classes) and could be extracted into a standalone library for any Docker client needing credential resolution.
Provides static methods to parse Dockerfiles and extract FROM base images and ARG definitions, with support for property interpolation (Maven-style ${...} placeholders). Handles multi-stage builds, chained ARGs, and platform-specific FROM lines. The parsing is line-based and does not rely on external libraries, making it lightweight and portable. This utility could be reused in any tool that needs to analyze Dockerfiles for dependency tracking or image metadata extraction.
A robust value object for parsing and validating Docker image names (e.g., registry.example.com/user/image:tag@sha256:digest). Handles all components: registry, user/org, image name, tag, and digest. Provides methods to get full name, simple name, tag, digest, and to check for specific patterns. The parsing is strict and well-tested. This class has no internal dependencies and could be extracted as a standalone utility for any Java project that manipulates Docker image references.
Defines a strategy interface for container readiness checks, with implementations for HTTP ping, TCP port, log matching, health check, and exit code. The WaitUtil orchestrates polling with configurable intervals and timeouts. Each checker is self-contained and implements a single method. This pattern is reusable in any container orchestration or testing framework that needs to wait for a container to become ready. The implementations are clean and could be extracted with minimal changes.
Handles parsing of port mapping specifications (e.g., '8080:80', '0.0.0.0:8080:80/tcp') and dynamic allocation of host ports. Supports exporting resolved port mappings to property files for use by other Maven plugins or test code. The inner class PropertyWriteHelper accumulates mappings and writes them atomically. This component is self-contained and could be reused in any Java application that needs to manage Docker port bindings or similar port-forwarding configurations.