Convert Figma logo to code with AI

fabric8io logodocker-maven-plugin

Maven plugin for running and creating Docker images

1,905
646
1,905
509

Top Related Projects

MATURE: A set of Maven tools for dealing with Dockerfiles

13,885

🏗 Build container images for your Java applications.

INACTIVE: A simple docker client for the JVM

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

Java Docker API Client

Gradle plugin for managing Docker images and containers.

Quick Overview

The fabric8io/docker-maven-plugin is a Maven plugin for building and managing Docker images and containers. It allows developers to integrate Docker operations seamlessly into their Maven build process, enabling easier containerization of Java applications.

Pros

  • Seamless integration with Maven build lifecycle
  • Supports various Docker operations like building, pushing, and running containers
  • Extensive configuration options for fine-grained control
  • Active development and community support

Cons

  • Steep learning curve for users new to Docker or Maven
  • Configuration can become complex for advanced use cases
  • Limited to Maven-based projects
  • May require additional setup for certain CI/CD environments

Code Examples

  1. Basic plugin configuration in pom.xml:
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.40.2</version>
  <configuration>
    <images>
      <image>
        <name>myapp:${project.version}</name>
        <build>
          <from>openjdk:11-jre</from>
          <assembly>
            <descriptorRef>artifact-with-dependencies</descriptorRef>
          </assembly>
          <cmd>java -jar ${project.artifactId}-${project.version}.jar</cmd>
        </build>
      </image>
    </images>
  </configuration>
</plugin>
  1. Running a Docker container:
<executions>
  <execution>
    <id>start</id>
    <phase>pre-integration-test</phase>
    <goals>
      <goal>start</goal>
    </goals>
  </execution>
</executions>
  1. Pushing an image to a registry:
<executions>
  <execution>
    <id>push</id>
    <phase>deploy</phase>
    <goals>
      <goal>push</goal>
    </goals>
  </execution>
</executions>

Getting Started

  1. Add the plugin to your pom.xml:
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.40.2</version>
</plugin>
  1. Configure the plugin with your Docker image details (as shown in the first code example).

  2. Run Maven commands to build and manage your Docker images:

mvn clean package docker:build  # Build Docker image
mvn docker:start               # Run Docker container
mvn docker:push                # Push image to registry

Competitor Comparisons

MATURE: A set of Maven tools for dealing with Dockerfiles

Pros of dockerfile-maven

  • Simpler configuration, focusing on Dockerfile-based builds
  • Better integration with Spotify's Docker client library
  • Supports multi-stage Dockerfiles out of the box

Cons of dockerfile-maven

  • Less flexible for complex Docker build scenarios
  • Limited support for Docker Compose or multi-container setups
  • Fewer advanced features compared to docker-maven-plugin

Code Comparison

dockerfile-maven:

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <version>${dockerfile-maven-version}</version>
  <executions>
    <execution>
      <id>default</id>
      <goals>
        <goal>build</goal>
        <goal>push</goal>
      </goals>
    </execution>
  </executions>
</plugin>

docker-maven-plugin:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>${docker.maven.plugin.version}</version>
  <configuration>
    <images>
      <image>
        <name>%g/%a:%l</name>
        <build>
          <dockerFile>Dockerfile</dockerFile>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

Both plugins aim to integrate Docker builds into Maven projects, but dockerfile-maven focuses on simplicity and Dockerfile-based builds, while docker-maven-plugin offers more advanced features and flexibility for complex Docker setups. The choice between them depends on the project's specific requirements and complexity.

13,885

🏗 Build container images for your Java applications.

Pros of Jib

  • No need for a Docker daemon or Docker installation
  • Faster build times due to layer caching and parallel execution
  • Reproducible builds across different environments

Cons of Jib

  • Less flexibility in customizing the Docker image build process
  • Limited support for complex multi-stage builds
  • Steeper learning curve for users familiar with Dockerfile-based workflows

Code Comparison

docker-maven-plugin:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <images>
      <image>
        <name>myapp:${project.version}</name>
        <build>
          <from>openjdk:11-jre</from>
          <assembly>
            <descriptorRef>artifact</descriptorRef>
          </assembly>
          <cmd>java -jar ${project.artifactId}-${project.version}.jar</cmd>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

Jib:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>jib-maven-plugin</artifactId>
  <configuration>
    <to>
      <image>myapp:${project.version}</image>
    </to>
    <container>
      <mainClass>com.example.MyApp</mainClass>
    </container>
  </configuration>
</plugin>

INACTIVE: A simple docker client for the JVM

Pros of docker-client

  • More flexible Java API for interacting with Docker, not limited to Maven builds
  • Supports a wider range of Docker operations and features
  • Can be used in various Java applications, not just for build processes

Cons of docker-client

  • Requires more manual configuration and code to set up Docker operations
  • Less integrated with Maven build lifecycle
  • May require more maintenance as Docker API changes

Code Comparison

docker-maven-plugin:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <images>
      <image>
        <name>myapp:${project.version}</name>
        <build>
          <from>openjdk:11-jre</from>
          <assembly>
            <descriptorRef>artifact</descriptorRef>
          </assembly>
          <cmd>java -jar ${project.artifactId}-${project.version}.jar</cmd>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

docker-client:

DockerClient docker = DefaultDockerClient.fromEnv().build();
docker.pull("openjdk:11-jre");

ContainerConfig containerConfig = ContainerConfig.builder()
    .image("openjdk:11-jre")
    .cmd("java", "-jar", "myapp.jar")
    .build();

ContainerCreation creation = docker.createContainer(containerConfig);
docker.startContainer(creation.id());

Testcontainers is a Java library that supports JUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

Pros of Testcontainers

  • Designed specifically for integration testing, providing a more focused and streamlined experience
  • Supports a wide range of databases and other services out of the box
  • Offers programmatic control over containers directly in test code

Cons of Testcontainers

  • Limited to testing scenarios, not suitable for general Docker image building or deployment
  • May require more setup and configuration for complex scenarios compared to Maven plugin approach

Code Comparison

Testcontainers:

@Container
PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:14");

@Test
void testWithPostgres() {
    // Use postgres.getJdbcUrl(), postgres.getUsername(), etc.
}

Docker Maven Plugin:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <configuration>
        <images>
            <image>
                <name>postgres:14</name>
                <!-- Additional configuration -->
            </image>
        </images>
    </configuration>
</plugin>

The Docker Maven Plugin is more versatile, allowing for Docker image building, pushing, and running containers as part of the Maven lifecycle. It's better suited for general Docker operations in a project. Testcontainers, on the other hand, excels in providing a seamless testing experience with Docker containers, offering more granular control within test code and a rich ecosystem of pre-configured containers for various services.

Java Docker API Client

Pros of docker-java

  • More flexible and can be used in various Java applications, not limited to Maven projects
  • Provides a comprehensive API for interacting with Docker, offering more granular control
  • Suitable for building custom Docker-related tools and integrations

Cons of docker-java

  • Requires more manual configuration and coding compared to the Maven plugin
  • Less integrated with the Maven build lifecycle
  • May have a steeper learning curve for developers primarily familiar with Maven

Code Comparison

docker-maven-plugin:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <images>
      <image>
        <name>myapp:${project.version}</name>
        <build>
          <from>openjdk:11-jre</from>
          <assembly>
            <descriptorRef>artifact-with-dependencies</descriptorRef>
          </assembly>
          <cmd>java -jar ${project.artifactId}-${project.version}.jar</cmd>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

docker-java:

DockerClient dockerClient = DockerClientBuilder.getInstance().build();
CreateContainerResponse container = dockerClient.createContainerCmd("myapp:latest")
    .withName("my-container")
    .exec();
dockerClient.startContainerCmd(container.getId()).exec();

The docker-maven-plugin example shows how to configure Docker image building within a Maven project, while the docker-java example demonstrates programmatic container creation and management using Java code.

Gradle plugin for managing Docker images and containers.

Pros of gradle-docker-plugin

  • Better integration with Gradle ecosystem and tasks
  • More flexible configuration options for Docker operations
  • Supports a wider range of Docker commands and operations

Cons of gradle-docker-plugin

  • Steeper learning curve for developers not familiar with Gradle
  • May require more setup and configuration compared to Maven-based solutions
  • Less widespread adoption in Java-centric projects

Code Comparison

docker-maven-plugin:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.40.2</version>
</plugin>

gradle-docker-plugin:

plugins {
  id 'com.bmuschko.docker-remote-api' version '7.3.0'
}

The docker-maven-plugin is configured in the pom.xml file, while the gradle-docker-plugin is added to the build.gradle file. The Maven plugin uses XML syntax, whereas the Gradle plugin uses Groovy DSL.

Both plugins offer similar core functionalities for Docker integration, but their implementation and usage differ based on their respective build systems. The choice between them often depends on the project's existing build tool and team preferences.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

docker-maven-plugin

Maven Central Circle CI Coverage Technical Debt

This is a Maven plugin for building Docker images and managing containers for integration tests. It works with Maven 3.0.5 and Docker 1.6.0 or later.

Goals

GoalDescriptionDefault Lifecycle Phase
docker:startCreate and start containerspre-integration-test
docker:stopStop and destroy containerspost-integration-test
docker:buildBuild imagesinstall
docker:watchWatch for doing rebuilds and restarts
docker:pushPush images to a registrydeploy
docker:removeRemove images from local docker hostpost-integration-test
docker:logsShow container logs
docker:sourceAttach docker build archive to Maven projectpackage
docker:saveSave image to a file
docker:tagTag imagesinstall
docker:volume-createCreate a volume to share data between containerspre-integration-test
docker:volume-removeRemove a created volumepost-integration-test
docker:copyCopy files and directories from a containerpost-integration-test

Documentation

  • The User Manual [PDF] has a detailed reference for all and everything.
  • The Introduction is a high-level overview of this plugin's features and provides a usage example. provided goals and possible configuration parameters.
  • Examples are below samples/ and contain example setups that you can use as blueprints for your projects.
  • ChangeLog has the release history of this plugin.
  • Contributing explains how you can contribute to this project. Pull requests are highly appreciated!
  • We publish nightly builds on maven central. Read How to use Docker Maven Plugin Snapshot artifacts.

Docker API Support

  • Docker 1.6 (v1.18) is the minimal required version
  • Docker 1.8.1 (v1.20) is required for docker:watch
  • Docker 1.9 (v1.21) is required for using custom networks and build args.