Docker — how can I copy a file from an image to a host?

Answering an old question for references. To copy a file from an image, create a temporary container, copy the file from it and then delete it:

id=$(docker create image-name)
docker cp $id:path -> local-tar-file
docker rm -v $id