title: Docker - how can I copy a file from an image to a host?
body: <p>My question is related to <a href="https://stackoverflow.com/questions/22049212/docker-copy-file-from-container-to-host">this question</a> on copying files from containers to hosts; I have a Dockerfile that fetches dependencies, compiles a build artifact from source, and runs an executable. I also want to copy the build artifact (in my case it's a <code>.zip</code> produced by <code>sbt dist</code> in '../target/`, but I think this question also applies to jars, binaries, etc. </p>
  
  <p><code>docker cp</code> works on containers, not images; do I need to start a container just to get a file out of it? In a script, I tried running <code>/bin/bash</code> in interactive mode in the background, copying the file out, and then killing the container, but this seems kludgey. Is there a better way?</p>
  
  <p>On the other hand, I would like to avoid unpacking a <code>.tar</code> file after running <code>docker save $IMAGENAME</code> just to get one file out (but that seems like the simplest, if slowest, option right now). </p>
  
  <p>I would use docker volumes, e.g.:</p>
  
  <pre><code>docker run -v hostdir:out $IMAGENAME /bin/cp/../blah.zip /out
  </code></pre>
  
  <p>but I'm running <code>boot2docker</code> in OSX and I don't know how to directly write to my mac host filesystem (read-write volumes are mounting inside my boot2docker VM, which means I can't easily share a script to extract <code>blah.zip</code> from an image with others. Thoughts?</p>