Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker cp for copying image files to file system (not running container) #34592

Closed
0xdevalias opened this issue Aug 22, 2017 · 1 comment
Closed
Labels
kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny

Comments

@0xdevalias
Copy link

0xdevalias commented Aug 22, 2017

It would be great if we could copy a file from an image to the local filesystem in the same way that we can copy to/from a running container.

Eg.

docker cp SOMECONTAINERREFERENCE:/foo/bar /local/foo/bat

I'm not sure what the best syntax would be for referencing the container (since it would need to handle /'s, which might be confused with filesystem) Perhaps even just a --fromContainer type flag would be sufficient?

I know that it can currently by done by making a temporary container, but that doesn't work well for super-minimal images (eg. FROM scratch)

# From: https://forums.docker.com/t/is-there-a-way-to-copy-a-file-from-an-image-to-the-local-filesystem-without-running-a-container/2841

docker run --name temp-container-name image-name /bin/true
docker cp temp-container-name:/path/to/manifest /local/path/to/manifest
docker rm temp-container-name

Currently it can be worked around by doing something like this, though it's obviously less than ideal:

TEMPCONT="fooTemp$(date +%s)"
docker run --name $TEMPCONT devalias/gobuster
docker export $TEMPCONT | tar -xvzf - gobuster
docker rm $TEMPCONT
@0xdevalias 0xdevalias changed the title Copy file directly from image to filesystem docker cp for copying image files to file system (not running container) Aug 22, 2017
@thaJeztah
Copy link
Member

This is a duplicate of #16079 (which may contain some useful information).

I know that it can currently by done by making a temporary container, but that doesn't work well for super-minimal images (eg. FROM scratch)

Copying from any image should work; there's no need to start the container, just creating a container is sufficient. For example:

# use the container's ID so that we don't have to come up with a name for it
CID=$(docker create <image-name>)
docker cp ${CID}:/path/to/manifest /local/path/to/manifest
docker rm ${CID}

I'm closing this one because it's a duplicate, but feel free to comment if you need more information

@thaJeztah thaJeztah added the kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny label Sep 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Functionality or other elements that the project doesn't currently have. Features are new and shiny
Projects
None yet
Development

No branches or pull requests

2 participants