Comments (4)
One way to achieve this goal would be to not build an uberjar and to supply a Dockerfile
of your own, which disables the plugin's logic of trying to generate one for you.
You can use the maven-dependency-plugin
to copy all of your dependencies to a directory, such as target/lib
:
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<useBaseVersion>false</useBaseVersion>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</plugin>
and then configure the maven-jar-plugin
to add a classpath entry to the jar's manifest that also refers to target/lib
:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<addMavenDescriptor>true</addMavenDescriptor>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>${jar.entrypoint}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Your Dockerfile should then copy the contents of target/lib
into the image, and also the jar containing your project's source code:
COPY target/lib /usr/share/your-service/lib
COPY target/your-jar.jar /usr/share/your-service/your-jar.jar
Finally, the entrypoint to your image would basically just run java -jar /path/to/your.jar
:
ENTRYPOINT ["/bin/bash", "-c", "exec /usr/bin/java $JVM_DEFAULT_ARGS $JVM_ARGS -jar /usr/share/your-service/your-jar.jar \"$@\"", "bash"]
Since each new command in the Dockerfile creates a new layer, this results in the layer containing your project JAR (which conceivably changes on each commit) to a layer containing just your project's dependencies (which conceivably change much less often).
This is the basic strategy that most of the images that we build internally in Spotify use.
from docker-maven-plugin.
@jorgemoralespou What kind of dependencies are you looking to add, eg debian packages or jars?
from docker-maven-plugin.
Maven compile and runtime dependencies, that is jar files.
Today, I'm using spring-boot and fat-jars but that means that every docker image has a new layer with a 38MB jar. That's spring, jetty, camel, guava and more. These normally do not change. And my microservice is only 28Kb. This is what's really changed.
From another maven docker plugin
1.1. Building Images
One purpose of this plugin is to create Docker images holding the actual application. This is done with the docker:build goal. It is easy to include build artifacts and their dependencies into an image. Therefore, this plugin uses the assembly descriptor format from the maven-assembly-plugin to specify the content which will be added from a sub-directory in the image (/maven by default). Images that are built with this plugin can be pushed to public or private Docker registries with docker:push.
https://fabric8io.github.io/docker-maven-plugin/
from docker-maven-plugin.
@mattnworb you should consider adding this ^ to README, as I'm sure a lot of users would like to build a self contained image with all dependencies included.
Great job btw :)
from docker-maven-plugin.
Related Issues (20)
- Not working with jdk11 HOT 4
- Failed to execute goal com.spotify:docker-maven-plugin:1.2.0:build HOT 5
- Problem connecting to Docker on Vagrant HOT 1
- 推送镜像至私服时,即使设置的imageTag,仍然会生成一个latest的tag,且两个tag的镜像id相同,如何设置才能覆盖latest的tag而只生成自己设置的tag呢 HOT 2
- how can i get git commit Id in lables
- =>
- Show Sending build context to Docker daemon ***GB HOT 1
- com.spotify.docker.client.shaded.org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html HOT 3
- k8s gitlab runner dose not work with docker maven plugin
- Authentication usernamenot support chinese HOT 1
- Support for Red Hat Enterprise Linux 8? HOT 1
- Can this plugin be used to publish docker image to docker.pkg.github.com HOT 1
- Status? HOT 1
- Schema specific part is opaque HOT 1
- Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project HOT 3
- Remote DOCKER_HOST configuration does not work with ssh protocol HOT 3
- How to building Docker Image in Maven Project of multi-module HOT 2
- gitlab ci not execute deploy with docker maven plugin HOT 1
- push image to registry fail HOT 1
- I am using docker maven plugin and I made intentionally error in application (bean creation exception) but always I am getting error in generic was saying Docker IO error [ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.32.0:start (docker-start) on project captcha-validator-integration-test: I/O Error: [***.azurecr.io/ssib/captcha-validator-service:1.2.0-SNAPSHOT] "service-captcha-validator": Timeout after 120460 ms while waiting on log out 'Started CaptchaValidatorApplication' -> [Help 1] [ERROR] [ERROR] How to display actual error in logs?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-maven-plugin.