Copy a file from container to host during build process

govin picture govin · Nov 24, 2014 · Viewed 7.2k times · Source

How do I copy files from a docker container to the host machine during docker build command?

As a part of building my docker image for my app, I'm running some tests inside it, and I would like to copy the output of the test run into the host (which is a continuous integration server) to do some reporting.

Answer

Javier Castellanos picture Javier Castellanos · Nov 25, 2014

I wouldn't run the tests during build, this will only increase the size of your image. I would recommend you to build the image and then run it mounting a host volume into the container and changing the working directory to the mount point.

docker run -v `pwd`/results:/results -w /results -t IMAGE test_script