1

I'm pulling with: docker pull <someimage>:<sometag>.

How can I validate that the remote tag has changed? So I can:

if [ CHECK_IF_REMOTE_TAG_IMAGE_HAS_CHANGED ]; then
    docker rm <someimage>:<sometag>
    docker pull <someimage>:<sometag>
fi

This comes in handy when using containers where the tag = :latest.

Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101
  • I'm surprised `docker search` doesn't return the last updated date for the container when that information is available on the website UI. If you could get that, combined with `docker history image:latest` should be enough – WilliamNHarvey Mar 18 '19 at 16:57
  • I am not sure if there's a reliable way unless the docker registry you use provide an API to retrieve latest version/tag. – Laksitha Ranasingha Mar 18 '19 at 17:00

2 Answers2

2

You can use container-diff to compare container images when both images are tagged with version latest.

victor gallet
  • 1,819
  • 17
  • 25
  • 1
    `latest` is not a version, It's yet another tag to label a build which didn't set a specific build tag. How does this work if the next version of `latest` build of the container has built with a specific tag like 1.0? – Laksitha Ranasingha Mar 18 '19 at 16:59
  • Thanks, unfortunately `container-diff` seems to not work at all. https://github.com/GoogleContainerTools/container-diff/issues/305 – Bob van Luijt Mar 18 '19 at 17:06
  • @BobvanLuijt literally just ran `container-diff` before dropping into this question. Try it with your images. – Gavin Miller Mar 18 '19 at 17:40
0
docker inspect -f {{.Id}} mongo:latest

Gives you the Id of the image which changes with each build [guessing docker build is what is used to change/modify image] - I am unsure of the behaviour when docker save is used. Sample Dockerfile to change the image mongo:latest and new tag as mongo:test1

FROM mongo:latest
COPY ./test.txt /tmp

$> docker build -t mongo:test1 .

Shell script to compare mongo:latest and mongo:test1

ID1=$(docker inspect -f {{.Id}} mongo:latest)
ID2=$(docker inspect -f {{.Id}} mongo:test1)

if [ "$ID1" == "$ID2" ]
then
    echo "Same Image"
else
    echo "Image changed"
fi

Output

Image changed

GreenThumb
  • 483
  • 1
  • 7
  • 25