I'm thinking of using Docker to build my dependencies on a continuous integration (CI) server, so that I don't have to install all the runtimes and libraries on the agents themselves. To achieve this I would need to copy the build artifacts that are built inside the container back into the host.
Is that possible?
If you just want to pull a file from an image (instead of a running container) you can do this:
docker run --rm <image> cat <source> > <local_dest>
This will bring up the container, write the new file, then remove the container. One drawback, however, is that the file permissions and modified date will not be preserved.
I am posting this for anyone that is using Docker for Mac. This is what worked for me:
Note that when I mount using
-v
thatbackup
directory is automatically created.I hope this is useful to someone someday. :)
Create a path where you want to copy the file and then use:
Create a data directory on the host system (outside the container) and mount this to a directory visible from inside the container. This places the files in a known location on the host system, and makes it easy for tools and applications on the host system to access the files
tldr;
Longer...
docker run
with a host volume,chown
the artifact,cp
the artifact to the host volume:This trick works because the
chown
invocation within the heredoc the takes$(id -u):$(id -g)
values from outside the running container; i.e., the docker host.The benefits over
docker cp
are:docker run --name
your container beforedocker container rm
afterI used PowerShell (Admin) with this command.
Example