Copying files to and from a Docker container

by Robert Bossaert

This week I was working on a project for an acquaintance, I had the project running inside a Docker container and needed a quick way to copy a few files over from the Docker container to the host machine. Turns out this is quite easy to accomplish.

docker cp <containerId>:<source-path> <destination-path>

You can obtain a list of all the active containers (and their id's) with:

docker ps

Example usage

docker cp 5aa160d4d5fa:/app/storage /Users/robert/Desktop

Of course if you end up sharing data between the host and Docker a lot, I would suggest looking at Docker volumes instead.