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/
EXPOSE 8080
ADD mydir/test.jar /tmp/test.jar
CMD bash -c 'java -jar /tmp/test.jar > /var/myVol/output.json'

  • Using docker, puppet and jenkins for continuous delivery and PROD deployment [closed]
  • Docker container not responding to anything
  • Building a docker image from inside a docker container
  • Docker compose environment variables specified with env_file parameter not working inside the dockerfile
  • How do you share privileged information with a docker container deployed as a worker on elastic beanstalk?
  • udp traffic with Iperf for haproxy
  • Docker expose port
  • How to get docker run to take the directory from the client machine to the host container?
  • Multiple docker images from SBT
  • Powershell devbox Magento installation using Docker
  • CoreOS : when pulling large docker image of size greater than 4 GB
  • Sharing directories in a Docker container both with a Dockerfile and after the container is running
  • 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.