I want to copy some file from a docker image without actually running a container from that image. Is it possible to do so? If yes, what would be steps required ?
There's not a docker cp for images because images are inmutable objects but:
you can create a non running container:
docker create --name cont1 some-image
docker cp cont1:/some/dir/file.tmp file.tmp
docker rm cont1
The full not accepted (now rejected) proposal for docker cp on images is here:
https://github.com/moby/moby/issues/16079
Here's a one-liner to copy a file from a Docker Image, through a container:
docker run --rm \
-v $(pwd):/binary my-image /bin/sh -c "cp /kube-bench /binary"
docker run --rm --entrypoint "/bin/sh" \
-v $(pwd):/binary kube-bench-image -c "cp /kube-bench /binary"
Both commands mounts the current directory in order to copy the file /kube-bench
to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With