Copy files from a Docker image to the host

Copy files from a Docker image to the host

For whatever reason if you would like to copy a file or directory from a Docker image to the host system, this is how you can do it

docker run --rm -v /path/on/image:/path/on/host name-of-your-docker-image:tag sh -c "cp -r /path/on/image /path/on/host"

For example, if I want to copy /app/build from the Docker image to /tmp/build on my host machine, I can do

docker run --rm -v /app/build:/tmp/build name-of-your-docker-image:tag sh -c "cp -r /app/build /tmp/build"