Paul Kenny
Paul Kenny

Reputation: 61

Searching a Docker Image for a particular file

Total newb to Docker. My question is, is there a way of searching a Docker image to see if there are any Jar files present.

If I understand correctly Docker images are built in layers and each layer does not necessarily belong to that image alone. My initial approach was to "save image > image.tar" to bring all the layers together and then recursively try and search the resulting tar for the pattern "*.jar". With a standard tar if, for example, I "less filename.tar" I can see right into all of the sub-directories of the tar. This does not seem to be the case with an image which has been tarballed.

Is there a way of doing this or am I misunderstanding fundamentally how an image is built and what happens to it when it is tarballed?

Edit: I actually want to do this specifically to the image rather than launching a docker container of the image and then searching that. Is this even possible?

Edit: OK I'll try and make this clearer. I have tried to take this approach:

1) Create a tarball from a docker image: docker save image > image.jar 2) Then I've tried to search the tar for jar files with this simple script:

#Will list and extract all jars from a tar file
arc=$1.tar; file='*.jar'; 

tar tvf $arc | grep -E "$file" && tar xvf $arc "$file"

3) This will work for a standard tarball but not for a docker tarball

Again I am totally new to docker and I just want to know if there is another way of doing this.

Upvotes: 5

Views: 21050

Answers (2)

James Griner
James Griner

Reputation: 11

The docker client has an "export" option. From a shell that has the environment configured to use the docker client run

docker export <your image> | tar tf - | grep etc/issue

which yields the following:

etc/issue

Upvotes: 1

Manoj Sahu
Manoj Sahu

Reputation: 2942

Do the following

  1. Run the image as docker run -it yourimage /bin/bash
  2. Now you are in interactive mode.
  3. Then use find / -name *.jar (if find command not available install it)

Upvotes: 13

Related Questions