logo docker-maven-plugin

Maven plugin for running and creating Docker images

homepage: github.com/fabric8io/docker-maven-plugin
fresh index:
last release: 1 month ago, first release: 6 years ago
packaging: maven-plugin
get this artifact from: central
see this artifact on: search.maven.org


Display vulnerabilities (snyk): Vulnerability check

This chart shows how much is this artifact used as a dependency in other Maven artifacts in Central repository and GitHub:


select version:

Add this snippet into pom.xml inside tag <project><build><plugins>:




Switch to artifact.
goals:
docker:build (phase: install)

Mojo for building a data image

docker:copy (phase: post-integration-test)

Mojo for copying file or directory from container. When called with true value of createContainers option, then all images which are configured in the project are iterated. For each image a temporary container is created (but not started) before the copying and is removed after completion of the copying, even if the copying failed. When called with false value of createContainers option (default value) and together with docker:start goal, then only the containers started by that goal are examined. Otherwise containers matching images configured in the project are searched and the copying is performed from the found containers only.

docker:help

Display help information on docker-maven-plugin. Call mvn docker:help -Ddetail=true -Dgoal=<goal-name> to display parameter details.

docker:logs

Mojo for printing logs of a container. By default the logs of all containers are shown interwoven with the time occured. The log output can be highly customized in the plugin configuration, please refer to the reference manual for documentation. This Mojo is intended for standalone usage. See {@link StartMojo} for how to enabling logging when starting containers.

docker:push (phase: deploy)

Goal for pushing a data-docker container

docker:remove (phase: post-integration-test)

Mojo for removing images. By default only data images are removed. Data images are images without a run configuration. By setting removeAll (property: docker.removeAll) also other images can be removed. In order to explicitly restrict the images to remove, use images to specify a (comma separated) list of images to remove.

docker:run (phase: pre-integration-test)

Alias for `docker:start`

docker:save
docker:source (phase: package)

Mojo for attaching one more source docker tar file to an artifact. If used in a lifecycle called 'docker-tar' the artifacts are attached without classifier. Otherwise the classifier is "docker" and, depending on the selected {@link BuildImageSelectMode}, the alias name of the build configuration.

docker:start (phase: pre-integration-test)

Goal for creating and starting a docker container. This goal evaluates the image configuration

docker:stop (phase: post-integration-test)

Mojo for stopping containers. If called together with docker:start (i.e. when configured for integration testing in a lifefcycle phase), then only the container started by this goal will be stopped and removed by default (this can be tuned with the system property docker.keepContainer). If this goal is called standalone, then all containers are stopped, for which images has been configured in the pom.xml

docker:tag (phase: install)

Goal for Tagging an image so that it becomes part of a repository.

docker:volume-create (phase: pre-integration-test)

Mojo to create named volumes, useful for preparing integration tests

docker:volume-remove (phase: post-integration-test)

Mojo to remove volumes created with {@link VolumeCreateMojo}

docker:watch

Mojo for watching source code changes. This Mojo does essentially two things when it detects a image content change: Rebuilding one or more images Restarting restarting one or more containers

Often used code snippets:

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.26.1</version>
  <configuration>
    <dockerHost>tcp://demo.stylefeng.cn:2376</dockerHost>
    <certPath>_dockerCerts</certPath>
    <images>
      <image>
        <alias>service</alias>
        <name>stylefeng/${project.artifactId}:latest</name>
        <build>
          <from>java:8</from>
          <assembly>
            <descriptor>docker-assembly.xml</descriptor>
          </assembly>
          <cmd>
            <shell>java -jar /maven/${project.artifactId}.jar</shell>
          </cmd>
        </build>
      </image>
    </images>
  </configuration>
</plugin>
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <configuration>
    <images>
      <image>
        <name>microservice-schedule</name>
        <build>
          <dockerFileDir>${docker.file.dir}</dockerFileDir>
          <assembly>
            <descriptorRef>artifact</descriptorRef>
          </assembly>
        </build>
      </image>
    </images>
  </configuration>
</plugin>
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.21.0</version>
  <configuration>
    <images>
      <image>
        <name>springcloud/${project.artifactId}</name>
        <build>
          <tags>
            <tag>latest</tag>
            <tag>${project.version}</tag>
          </tags>
          <from>springcloud/openjdk:2.0.0.RELEASE</from>
          <volumes>
            <volume>/tmp</volume>
          </volumes>
          <env>
            <LANG>C.UTF-8</LANG>
          </env>
          <entryPoint>
            <exec>
              <arg>java</arg>
              <arg>-jar</arg>
              <arg>/maven/spring-cloud-dataflow-server.jar</arg>
            </exec>
          </entryPoint>
          <assembly>
            <name>maven</name>
            <descriptor>assembly.xml</descriptor>
            <targetDir>/</targetDir>
          </assembly>
        </build>
      </image>
    </images>
  </configuration>
</plugin>
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <images>
      <image>
        <name>springboot-jwt</name>
        <alias>springboot-jwt</alias>
        <build>
          <filter>@</filter>
          <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
          <assembly>
            <descriptorRef>artifact</descriptorRef>
          </assembly>
        </build>
        <run>
          <namingStrategy>alias</namingStrategy>
          <ports>
            <port>${tomcat.port}:8080</port>
          </ports>
          <wait>
            <http>
              <url>http://${tomcat.ip}:${tomcat.port}/health</url>
            </http>
            <time>90000</time>
          </wait>
        </run>
      </image>
    </images>
  </configuration>
</plugin>
<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.14.2</version>
  <configuration>
    <images>
      <image>
        <name>${docker.image}</name>
        <build>
          <from>anapsix/alpine-java:8</from>
          <volumes>
            <volume>/tmp</volume>
          </volumes>
          <entryPoint>
            <exec>
              <arg>java</arg>
              <arg>-jar</arg>
              <arg>/maven/demo.jar</arg>
            </exec>
          </entryPoint>
          <assembly>
            <descriptor>assembly.xml</descriptor>
          </assembly>
        </build>
      </image>
    </images>
  </configuration>
</plugin>

© Jiri Pinkas 2015 - 2022. All rights reserved! Admin login To submit bugs / feature requests please use this github page
related: JavaVids | Top Java Blogs | Java školení
Apache and Apache Maven are trademarks of the Apache Software Foundation. The Central Repository is a service mark of Sonatype, Inc.