Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerize generic Spring boot app with maven plugin #339

Closed
computerlyrik opened this issue Nov 26, 2015 · 4 comments
Closed

Dockerize generic Spring boot app with maven plugin #339

computerlyrik opened this issue Nov 26, 2015 · 4 comments

Comments

@computerlyrik
Copy link
Contributor

Hi!
I did some testing but cannot achive the following:

A Spring Boot app consists only of a runnable Jar. So the Dockerfile as suggested by Spring itself as follows:

FROM java:8
VOLUME /tmp
ADD gs-spring-boot-docker-0.1.0.jar app.jar
RUN bash -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

I want to transform this into <build></build> to *get rid of the Dockerfile and make use of the many nice maven properties.

Now, i am still hanging on putting the resulting artifact-0.0.1-SNAPSHOT.jar as app.jar to the docker container.

S/o got any help? How do i configure my assembly?

Yes, i read http://ro14nd.de/docker-maven-plugin/docker-build.html but i do not understand the handling of assemblyDescriptorRef and such.

@rhuss
Copy link
Collaborator

rhuss commented Nov 26, 2015

Try something like this in the build configuration:

<build>
  <from>${image}</from>
  <assembly>
    <basedir>/</basedir>
    <inline>
      <id>spring-boot-jar</id>
      <dependencySets>
        <dependencySet>
          <useProjectArtifact>true</useProjectArtifact>
          <includes>
            <include>mygroup:app</include>
          </includes>
          <outputDirectory>.</outputDirectory>
          <outputFileNameMapping>app.jar</outputFileNameMapping>
        </dependencySet>
      </dependencySets>
    </inline>
  </assembly>
</build>

Note the outputFileNameMapping config. For assemblies you can everything as described for the maven-assembly-plugin

basedir puts it into / into your image (by default this is /maven).

BTW, soon we will extend direct Dockerfile support with placeholders, also for an assembly so things might get even easier.

@computerlyrik
Copy link
Contributor Author

@rhuss Thanks a lot for the fast answer.

I am getting the following error:

 Failed to execute goal org.jolokia:docker-maven-plugin:0.13.6:build (build-image) on project myproject: Failed to create assembly for docker image: Error adding file 'de.computerlyrik.mygroup:myproject:jar:0.0.1-SNAPSHOT' to archive: /home/cf/projects/myproject/target/classes isn't a file. with mode dir -> [Help 1]

With the following config

                            <build>
                                <from>java:8</from>
                                <assembly>
                                    <basedir>/</basedir>
                                    <inline>
                                        <id>spring-boot-jar</id>
                                        <dependencySets>
                                            <dependencySet>
                                                <useProjectArtifact>true</useProjectArtifact>
                                                <includes>
                                                    <include>${project.groupId}:${project.artifactId}</include>
                                                </includes>
                                                <outputDirectory>.</outputDirectory>
                                                <outputFileNameMapping>app.jar</outputFileNameMapping>
                                            </dependencySet>
                                        </dependencySets>
                                    </inline>
                                </assembly>
                            </build>

@computerlyrik
Copy link
Contributor Author

Btw i am running mvn clean package docker:build

@computerlyrik
Copy link
Contributor Author

Okay. Fail detection complete.

Do NEVER run the docker:build target on compile time :/

Thanks, this above example works!

leusonmario pushed a commit to leusonmario/docker-maven-plugin that referenced this issue Aug 18, 2018
leusonmario pushed a commit to leusonmario/docker-maven-plugin that referenced this issue Aug 18, 2018
integrate revamped authentication support from docker-client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants