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

前端 未结 8 739
庸人自扰
庸人自扰 2020-12-02 05:56

My question is related to this question on copying files from containers to hosts; I have a Dockerfile that fetches dependencies, compiles a build artifact from source, and

8条回答
  •  感动是毒
    2020-12-02 06:45

    A much faster option is to copy the file from running container to a mounted volume:

    docker run -v $PWD:/opt/mount --rm --entrypoint cp image:version /data/libraries.tgz /opt/mount/libraries.tgz
    

    real 0m0.446s

    ** VS **

    docker run --rm --entrypoint cat image:version /data/libraries.tgz > libraries.tgz
    

    real 0m9.014s

提交回复
热议问题