1

I have a set of Docker base images within my organization. I have one per technology stack (Java or Python for example). I can also build these base images for a specific version of Java and push it to the artifactory.

We will then have different projects who will use these base images and construc their Dockerfile. We now want to somehow ensure during the build process of those projects that they did infact use the base image that I created in their Dockerfile!

For example., if the image that I created for Java on Alipine is called

java-8-alpine-3

Then the project that would need a Java runtime should have this as their first line:

FROM java-8-alipne-3

How do I ensure that this is the case? In other words, how can I inspect the images to check for usage of such properties?

joesan
  • 13,963
  • 27
  • 95
  • 232

3 Answers3

1

well for a particular image you can use century link image which will reverse engineer the docker image

docker run -v /var/run/docker.sock:/var/run/docker.sock \
centurylink/dockerfile-from-image <IMAGE_TAG_OR_ID>

click here for more info

unfortunately century link image use docker tree command which is depreciated so the other solution is to use this

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock 
nate/dockviz images -t

it will display all the layers you can go through inspecting all the layers then .

varnit
  • 1,859
  • 10
  • 21
  • What is the $INSTANCE_ID? Is is the name of the Image that I wish to inspect? – joesan Aug 22 '17 at 14:29
  • Is the .Config.Image flag corresponds to the FROM tag with which I can check if my base image is used? – joesan Aug 22 '17 at 14:30
  • well instance_id is the name of the docker instance that is running – varnit Aug 22 '17 at 14:30
  • I want to do the check on the Docker Image and not on the running container instance – joesan Aug 22 '17 at 14:31
  • Nope! That is not what I want! I want to be able to do that on the static image and not on the running container! – joesan Aug 22 '17 at 14:33
  • sorry for the misunderstanding can you try this: docker image inspect [OPTIONS] IMAGE [IMAGE...] – varnit Aug 22 '17 at 14:34
  • Docker image inspect seems also not what I want! I get a JSON back, but from the JSON I cannot say what its FROM command is – joesan Aug 22 '17 at 14:37
0

You cannot get FROM line just having the image.

You can use docker history --no-trunc image_name to get the history of an image, but you can't get FROM line.

Take a look to this thread on Docker forum for further information: https://forums.docker.com/t/how-can-i-view-the-dockerfile-in-an-image/5687/3

kstromeiraos
  • 4,659
  • 21
  • 26
-1

if you just need to know the FROM xxx line used to build your images, just do

docker history --no-trunc my_image

and you will get that information

The doc

https://docs.docker.com/engine/reference/commandline/history/

Edit:

https://hub.docker.com/r/dduvnjak/dockerfile-from-image/

is a fixed version of

https://github.com/CenturyLinkLabs/dockerfile-from-image/issues/14

which no longer works

for example

$ docker run -v /var/run/docker.sock:/var/run/docker.sock dduvnjak/dockerfile-from-image k3ck3c/nethogs FROM alpine:latest RUN apk update && apk add wget&& wget --no-check-certificate -c http://github.com/raboof/nethogs/archive/v0.8.1.tar.gz && tar zvxf v0.8.1.tar.gz && cd ./nethogs-0.8.1/ && echo "export ARCH=x86" >> Makefile && apk add sudo linux-headers ncurses-dev libpcap-dev make g++&& echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && apk update && apk add libpcap libstdc++ libgcc nethogs@testing&& make && sudo make install&& apk del sudo g++ make linux-headers ncurses-dev libpcap-dev libpcap libgcc libstdc++ && rm -rf /var/cache/apk/* ./nethogs-0.8.1/

shows the

FROM

line correctly

or just

$ docker run -v /var/run/docker.sock:/var/run/docker.sock dduvnjak/dockerfile-from-image k3ck3c/nethogs | grep FROM FROM alpine:latest

user2915097
  • 30,758
  • 6
  • 57
  • 59
  • 1
    Actually you can't get `FROM xxx` line with `docker history --no-trunc my_image` – kstromeiraos Aug 22 '17 at 14:33
  • https://github.com/CenturyLinkLabs/dockerfile-from-image used to show this, but it is broken at the moment, and it does nearly the same things, see the code – user2915097 Aug 22 '17 at 16:25
  • the code https://github.com/CenturyLinkLabs/dockerfile-from-image/blob/master/dockerfile-from-image.rb – user2915097 Aug 22 '17 at 17:02