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

前端 未结 8 721
庸人自扰
庸人自扰 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:43

    Unfortunately there doesn't seem to be a way to copy files directly from Docker images. You need to create a container first and then copy the file from the container.

    However, if your image contains a cat command (and it will do in many cases), you can do it with a single command:

    docker run --rm --entrypoint cat yourimage  /path/to/file > path/to/destination
    

    If your image doesn't contain cat, simply create a container and use the docker cp command as suggested in Igor's answer.

提交回复
热议问题