copy file from container to the host before the container dies

I am pretty novice to the docker container. I am trying to build an image which is running a jar file. I want to pass the output file to the host for further processing but the container exits as soon as it finish the command.
1- what is the best practices for this problem?
2- is there any way to pass the file name dynamically instead of hard coding in the docker file.
here is my Dockerfile:

FROM mybase:latest
VOLUME /root/:/var/myVol/
ADD mydir/test.jar /tmp/test.jar
CMD bash -c 'java -jar /tmp/test.jar > /var/myVol/output.json'

  • Add Domain name to Docker Cloud node
  • can I mount subdir of volume in docker run command
  • Docker error while creating couchbase - ulimit: open files: cannot modify limit: Operation not permitted
  • Managing container dependencies on startup
  • Docker compose wants engine > 1.10.0 but it already has engine 1.12.3
  • Docker PHP image. lstat docker-php-source: no such file or directory
  • Datanode denied communication with namenode because hostname cannot be resolved
  • Docker image for windows with oracle12
  • How to retrieve metrics from Postfix in Docker Container
  • Application manager in YARN setup
  • Docker application live upgrade
  • Docker postgres does not run init file in docker-entrypoint-initdb.d
  • One Solution collect form web for “copy file from container to the host before the container dies”

    You can just mount output file as a volume using -v option. Your program will write directly to the output file on the host without any need to copy anything anywhere

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.