How to check for Certain Properties in Docker Imag

2019-08-09 11:22发布

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?

标签: docker
3条回答
看我几分像从前
2楼-- · 2019-08-09 12:08

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 .

查看更多
Deceive 欺骗
3楼-- · 2019-08-09 12:10

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

查看更多
爷、活的狠高调
4楼-- · 2019-08-09 12:12

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

查看更多
登录 后发表回答