Reputation: 617
Is it possible to tell if a Docker image was built locally or pulled from a remote repository?
Clarification: We have large images (15+ GB) that are automated builds in Docker HUB. During development/testing it's often faster to build these images locally but using the same tags so that they can be used in building downstream images. It would be useful if we could to determine if a given image was built locally or downstream.
Upvotes: 3
Views: 1861
Reputation: 13248
Given this minimal Dockerfile
From busybox
Run echo "My first command"
Run echo "My second command"
Run echo "My third command"
You can build a docker image with:
$ docker build -t abdelghany/myimage .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abdelghany/myimage latest 159379ab5770 5 minutes ago 1.106 MB
busybox latest c75bebcdd211 3 weeks ago 1.106 MB
Here is docker history
of this locally built image:
$ docker history abdelghany/myimage
IMAGE CREATED CREATED BY SIZE COMMENT
7a352943082a 8 seconds ago /bin/sh -c echo "My third command" 0 B
6e59deae3839 8 seconds ago /bin/sh -c echo "My second command" 0 B
24df2c17994f 9 seconds ago /bin/sh -c echo "My first command" 0 B
c75bebcdd211 3 weeks ago /bin/sh -c #(nop) CMD ["sh"] 0 B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:5dde1d6e0f6362350d 1.106 MB
Now, push image to a registry, delete it locally, then pull it again.
$ docker push abdelghany/myimage
$ docker rmi abdelghany/myimage
$ docker pull abdelghany/myimage
Here is the docker history
of the pulled image:
$ docker history abdelghany/myimage
IMAGE CREATED CREATED BY SIZE COMMENT
159379ab5770 3 minutes ago /bin/sh -c echo "My third command" 0 B
<missing> 3 minutes ago /bin/sh -c echo "My second command" 0 B
<missing> 3 minutes ago /bin/sh -c echo "My first command" 0 B
<missing> 3 weeks ago /bin/sh -c #(nop) CMD ["sh"] 0 B
<missing> 3 weeks ago /bin/sh -c #(nop) ADD file:5dde1d6e0f6362350d 1.106 MB
Explanation: docker history shows all the commands that was used to create the image layers. For locally built images, each command is associated with an intermediate image to be used in build cache (so the next time you build the image on that docker host it uses the intermediate images from cache).
When moving images around (i.e pushing and pulling), you only move the final image so when you look at the history it shows <missing>
to indicate there is no intermediate image associated with this command, which indicates it was not built on this docker host.
Upvotes: 4
Reputation: 26
You may want to see if docker history
gives you the information you are looking for.
This command gives you the commands executed by the Dockerfile, so the MAINTAINERS
tag (or the more correct LABEL maintainer
) may appear in the history to give you some insight into the image creator.
Upvotes: 0