question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

configuration->images->image->build->assembly->targetDir not working despite no dockerfile

See original GitHub issue

Using XML config (not Dockerfile), the plugin consistently builds an image containing the jar file under /maven/ directory, despite having targetDir configured to /

Info

The docs say that targetDir defines where the artifact is included, but I can’t get the plugin to accept my value, which is / or the root.

I’ve tried both <targetDir></targetDir> and <targetDir>/</targetDir>

It ignores the setting and places the jar in the /maven/ directory like this:

[INFO] DOCKER> Step 2/5 : COPY maven /maven/

I see in the docs there’s a comment that the targetDir is ignored when a Dockerfile is in use, but in this case there isn’t.

I can work around this by declaring <name>/</name> which gives me

[INFO] DOCKER> Step 2/5 : COPY / ///

and the jar ends up in root.

Took me a while to discover that. I assume this would be instantly reproducible in any project. Here’s my XML:

           <plugin>
                <groupId>io.fabric8</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <configuration>
                    <logStdout>true</logStdout>
                    <outputDirectory>target/docker-build</outputDirectory>
                    <verbose>true</verbose>
                    <images>
                        <image>
                            <name>${gem.docker.registry}/tardis/tardis</name>
                            <build>
                                <tags>
                                    <tag>latest</tag>
                                    <tag>${git.branch}-${project.version}</tag>
                                    <tag>${git.branch}-latest</tag>
                                </tags>
                                <entryPoint>
                                    <exec>
                                        <arg>java</arg>
                                        <arg>-Dlogging.file=/logs/tardis.log</arg>
                                        <arg>-Djava.security.auth.login.config=/config/login.conf</arg>
                                        <arg>-Djava.security.krb5.conf=/config/krb5.conf</arg>
                                        <arg>-jar</arg>
                                        <arg>tardis.jar</arg>
                                    </exec>
                                </entryPoint>
                                <from>frolvlad/alpine-oraclejdk8:slim</from>
                                <volumes>
                                    <volume>/tmp</volume>
                                </volumes>
                                <runCmds>
                                    <run>mkdir /logs</run>
                                </runCmds>
                                <assembly>
                                    <targetDir></targetDir>
                                    <inline>
                                        <files>
                                            <file>
                                                <source>${project.build.directory}/${build.finalName}.${project.packaging}</source>
                                                <outputDirectory>/</outputDirectory>
                                                <destName>tardis.jar</destName>
                                            </file>
                                        </files>
                                        <fileSet>
                                            <directory>${project.build.directory}/config</directory>
                                            <outputDirectory>/config</outputDirectory>
                                        </fileSet>
                                    </inline>
                                </assembly>
                            </build>
                        </image>
                    </images>
                </configuration>
            </plugin>
  • d-m-p version : 0.22.1
  • Maven version (mvn -v) : 3.3.9
  • Docker version : 17.06.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
rhusscommented, Sep 18, 2017

You mapping were simply a bit off. I fixed it with this:

                               <assembly>
                                    <targetDir>/</targetDir>
                                    <inline>
                                        <files>
                                            <file>
                                                <source>${project.build.directory}/${build.finalName}.${project.packaging}</source>
                                                <outputDirectory>.</outputDirectory>
                                                <destName>test.jar</destName>
                                            </file>
                                        </files>
                                        <fileSet>
                                            <directory>${project.build.directory}/classes/config</directory>
                                            <outputDirectory>config</outputDirectory>
                                            <includes>
                                                <include>**/login.conf</include>
                                                <include>**/krb5.conf</include>
                                            </includes>
                                        </fileSet>
                                    </inline>
                                </assembly>
  • targetDir to /
  • All other output pathes should be relative
  • You config mapping was faulty:
    • The config filres are copied to target/classes as they are in src/main/resources.
    • config was mentioned twice: In include and in the directory
  • No need to give the assembly a null name.

The snippet above works for me when running mvn package.

Does it work for you, too ?

0reactions
adam42acommented, Sep 20, 2017

Right! Sorry, I’m new to docker. I thought that tar image was the same as the final docker image but obviously not. Trying to take shortcuts were there weren’t any 👎

I think what was also concerning me was the directory name ‘maven’ which just seemed wrong but now I realise it’s purely a temporary artifact of the plugin process.

Thanks for the help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

docker build exits successfully but no built image show up in ...
If I run docker image ls , though, the images do show up. Reinstalled Docker and the problem has gone away, for now...
Read more >
docker build - Docker Documentation
In this scenario, there is no context. By default the docker build command will look for a Dockerfile at the root of the...
Read more >
Docker - Container is not running - Stack Overflow
The container will always exit (stop running) if the command is non-blocking, this is the case with bash. In this case, a workaround...
Read more >
9 Common Dockerfile Mistakes - Runnablog
We work with Dockerfiles on a daily basis; all the code we run for ... RUN apt-get update && \ apt-get install -y...
Read more >
How to Debug and Fix Common Docker Issues - DigitalOcean
In this troubleshooting guide aimed at people new to Docker, you'll troubleshoot problems when building Docker images, resolve naming ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found