Unable to copy files in the target directory after tests have completed from container to host.
If this is already currently possible with the plugin, please let me know.
mvn -v) :Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T08:41:47-08:00)
Maven home: /Users/axiom/tools/JavaLib/main/build/apache-maven-3.3.9
Java version: 1.8.0_92, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac"
Docker version : 17.03.1-ce, build c6d412e
If it's a feature request, what is your use case :
The use case I have is I'd like to copy the test results in my target directory in the post-integration-test phase from within the running container to the host.
Would be great if we could do something like this -
<executions>
<execution>
<id>copy</id>
<phase>post-integration-test</phase>
<configuration>
<fromContainerDirectory>./target/results/</fromContainerDirectory>
<toHostDirectory>./target/results</toHostDirectory>
</configuration>
<goals>
<goal>cp</goal>
</goals>
</execution>
</executions>
I just realized that the solution I proposed above won't work in my case. Please disregard it.
How can I keep the container running after maven exits?
I would like to copy the files I need from the container before stopping the container.
docker cp <containerId>:/file/path/within/container /host/path/target
I think the best solution is to use a docker volume mount to share the directory inside your container that contains the files you want, with the host machine.
The d-m-p documentation is here: https://dmp.fabric8.io/#start-volumes
Your XML section might look like this:
...
<volumes>
<bind>
<volume>${project.basedir}/target:${container.work.dir}/target/results</volume>
</bind>
</volumes>
...
Then, when your running container writes to its target/results directory, Docker will automatically write those files to your host machine's target/results directory, and when the container stops, those files will still be there for you.
This will work with the existing docker-maven-plugin.
Thanks @Gengar003! That suggestion definitely put me on the right track!
with volume-bind mounts you have another problem if your container is running under a $user account.
Because the $user account can't write into the target/results directory.
Therefore a copy-goal will be useful.
In my case i want to measure code-coverage with a jacoco agent and pull the results out of the container to merge them with other jacoco-results.
I work around that by adding a chmod a+rwx target/results. I do that by having a script in my project that reads something like:
testrun.sh
the-actual-command-i-want --some-arg
chmod a+rwx target/results
Then when I start a container that will write to target/results, I also:
testrun.shtestrun.sh instead of the actual commandThis leaves the contents of the target/results directory world-accessible, so that no matter which user was used inside the container, the host will be able to read them.
This does assume that the container you're running can chmod. If not, you could (although this starts to get clumsy) run another container after the first - something simple like alpine - and just have _it_ run chmod a+rwx target/results as root.
This feature is still looking must have for me (I'm using builder image and need to copy built binaries from container to the maven project) because I use remote Docker instance and solution suggested in that comment doesn't work for such case while docker cp command works fine. Is it possible to reopen this feature request (issue) and implement it?
Note: I cannot use multi-stage build due to old version of Docker (RHEL 7)
I started implementation of this feature in https://github.com/fabric8io/docker-maven-plugin/compare/master...mabrarov:copy_mojo.
Working example with usage of new version of docker-maven-plugin can be found in feature/docker-maven-plugin-copy-mojo branch of mabrarov/maven-docker-builder.
Volunteers wanted to complete and polish the changes. What's missing at the moment:
io.fabric8.maven.docker.config.handler.property.PropertyConfigHandler class needs to be extended - need to implement loading of io.fabric8.maven.docker.config.CopyConfiguration from given io.fabric8.maven.docker.config.handler.property.ValueProvider.copy goal.Here is one more (more complicated and closer to real project) sample using docker builder pattern and copy goal of d-m-p: https://github.com/mabrarov/redis-builder
@testphreak,
Could you please reopen this issue? I don't like duplicates, so prefer to not open a new issue, just because the old closed one was found not needed at the time it was closed.
Thank you.
@mabrarov reopened
I opened pull request #1405. Though it lacks some of the things, but it already works for me in mabrarov/redis-builder.
I suggest to look at mabrarov/redis-builder for those who wants to try copy goal implemented in pull request #1405. mabrarov/redis-builder contains travis/settings.xml Maven configuration file which points to Bintray repository where d-m-p built from the pull request #1405 can be found:
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.34-dev</version>
</plugin>
When this will be released?
Hi @qalinn,
When this will be released?
Refer to https://github.com/fabric8io/docker-maven-plugin/pull/1412#issuecomment-740195896. I can work on pull request #1405 and complete it, but it doesn't look like it will be accepted before the mentioned cleanup.
Most helpful comment
@mabrarov reopened