当前位置: 首页 > 软件库 > 云计算 > >

dockerfile-maven

授权协议 Apache-2.0 License
开发语言 Java
所属分类 云计算
软件类型 开源软件
地区 不详
投 递 者 赏高格
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Dockerfile Maven

Status: mature

At this point, we're not developing or accepting new features or even fixing non-critical bugs.

This Maven plugin integrates Maven with Docker.

The design goals are:

  • Don't do anything fancy. Dockerfiles are how you buildDocker projects; that's what this plugin uses. They aremandatory.
  • Make the Docker build process integrate with the Maven buildprocess. If you bind the default phases, when you type mvn package, you get a Docker image. When you type mvn deploy,your image gets pushed.
  • Make the goals remember what you are doing. You can type mvn dockerfile:build and later mvn dockerfile:tag and later mvn dockerfile:push without problems. This also eliminates the needfor something like mvn dockerfile:build -DalsoPush; instead youcan just say mvn dockerfile:build dockerfile:push.
  • Integrate with the Maven build reactor. You can depend on theDocker image of one project in another project, and Maven willbuild the projects in the correct order. This is useful when youwant to run integration tests involving multiple services.

This project adheres to the Open Code of Conduct.By participating, you are expected to honor this code.

See the changelog for a list of releases

Set-up

This plugin requires Java 7 or later and Apache Maven 3 or later (dockerfile-maven-plugin <=1.4.6 needsMaven >= 3, and for other cases, Maven >= 3.5.2). To run the integration tests or to use the plugin in practice, a workingDocker set-up is needed.

Example

For more examples, see the integration test directory.

In particular, the advanced test showcases afull service consisting of two micro-services that are integrationtested using helios-testing.

This configures the actual plugin to build your image with mvn package and push it with mvn deploy. Of course you can also saymvn dockerfile:build explicitly.

<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>
  <configuration>
    <repository>spotify/foobar</repository>
    <tag>${project.version}</tag>
    <buildArgs>
      <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
  </configuration>
</plugin>

A corresponding Dockerfile could look like:

FROM openjdk:8-jre
MAINTAINER David Flemström <dflemstr@spotify.com>

ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/myservice/myservice.jar"]

# Add Maven dependencies (not shaded into the artifact; Docker-cached)
ADD target/lib           /usr/share/myservice/lib
# Add the service itself
ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/myservice/myservice.jar

Important note

The most Maven-ish way to reference the build artifact would probablybe to use the project.build.directory variable for referencing the'target'-directory. However, this results in an absolute path, whichis not supported by the ADD command in the Dockerfile. Any such sourcemust be inside the context of the Docker build and therefor must bereferenced by a relative path. See https://github.com/spotify/dockerfile-maven/issues/101

Do not use ${project.build.directory} as a way to reference yourbuild directory.

What does it give me?

There are many advantages to using this plugin for your builds.

Faster build times

This plugin lets you leverage Docker cache more consistently, vastlyspeeding up your builds by letting you cache Maven dependencies inyour image. It also encourages avoiding the maven-shade-plugin,which also greatly speeds up builds.

Consistent build lifecycle

You no longer have to say something like:

mvn package
mvn dockerfile:build
mvn verify
mvn dockerfile:push
mvn deploy

Instead, it is simply enough to say:

mvn deploy

With the basic configuration, this will make sure that the image isbuilt and pushed at the correct times.

Depend on Docker images of other services

You can depend on the Docker information of another project, becausethis plugin attaches project metadata when it builds Docker images.Simply add this information to any project:

<dependency>
  <groupId>com.spotify</groupId>
  <artifactId>foobar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <type>docker-info</type>
</dependency>

Now, you can read information about the Docker image of the projectthat you depended on:

String imageName = getResource("META-INF/docker/com.spotify/foobar/image-name");

This is great for an integration test where you want the latestversion of another project's Docker image.

Note that you have to register a Maven extension in your POM (or aparent POM) in order for the docker-info type to be supported:

<build>
  <extensions>
    <extension>
      <groupId>com.spotify</groupId>
      <artifactId>dockerfile-maven-extension</artifactId>
      <version>${version}</version>
    </extension>
  </extensions>
</build>

Use other Docker tools that rely on Dockerfiles

Your project(s) look like so:

a/
  Dockerfile
  pom.xml
b/
  Dockerfile
  pom.xml

You can now use these projects with Fig or docker-compose or someother system that works with Dockerfiles. For example, adocker-compose.yml might look like:

service-a:
  build: a/
  ports:
  - '80'

service-b:
  build: b/
  links:
  - service-a

Now, docker-compose up and docker-compose build will work asexpected.

Usage

See usage docs.

Authentication

See authentication docs.

Releasing

To cut the Maven release:

mvn clean [-B -Dinvoker.skip -DskipTests -Darguments='-Dinvoker.skip -DskipTests'] \
  -Dgpg.keyname=<key ID used for signing artifacts> \
  release:clean release:prepare release:perform

We use gren to create Releases in Github:

gren release
 相关资料
  • Dockerfile市场主要是为了方便大家正确的填写Dockerfile而提供的一些例子,当然您也可以直接下载该市场里的已经制作好的相关Dockerfile文件放到您的项目里 创建Dockerfile 不多说了,直接看图吧...

  • Dockerfile best practices Writing production-worthy Dockerfiles is, unfortunately, not as simple as you would imagine. Most Docker images in the wild fail here, and even professionals often[1] get[2]

  • 错误消息:未能部署“Dockerfile:DockerNew”:com。fasterxml。杰克逊。数据绑定。JsonMappingException:数值(4294967295)超出int的范围(-2147483648-2147483647)在[源:(okio.RealBufferedSource$1);行:8,列:34](通过引用链:com.github.dockerjava.api.mode

  • 主要内容:指令详解什么是 Dockerfile? Dockerfile 是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明。 使用 Dockerfile 定制镜像 这里仅讲解如何运行 Dockerfile 文件来定制一个镜像,具体 Dockerfile 文件内指令详解,将在下一节中介绍,这里你只要知道构建的流程即可。 1、下面以定制一个 nginx 镜像(构建好的镜像内会有一个 /usr/s

  • Create a MATLAB Container Image Requirements You must perform these steps on a Linux platform.Before starting, you must install the following on the client platform Docker Git Introduction The followi

  • 什么是云端 Dockerfile? 用户可以维护一份 Dockerfile 在 DaoCloud 云端,我们称之为云端 Dockerfile,它比较适用于下面这些场景: 用户的代码仓库中没有 Dockerfile 用户需要用一份不同于代码仓库中的 Dockerfile 构建镜像 构建过程中需要引用一些隐私数据,比如密码,不适合保存在代码仓库中 需要调试 Dockerfile,每次都要更新代码仓库效