Skip to content

Instantly share code, notes, and snippets.

@ulexxander
Created May 17, 2024 10:04
Show Gist options
  • Save ulexxander/061e3f6753f8c2b45c6e4ca1312e2318 to your computer and use it in GitHub Desktop.
Save ulexxander/061e3f6753f8c2b45c6e4ca1312e2318 to your computer and use it in GitHub Desktop.
Simple shell script to diff Docker image layers, see which layers was changed between two images.
#!/bin/sh
# Usage:
# docker-layers-diff image-1 image-2
set -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Missing 1 / 2 args"
exit 1
fi
echo "Pulling images"
docker pull "$1" -q
docker pull "$2" -q
docker inspect $1 | jq '.[].RootFS.Layers' > /tmp/${USER}-$$-docker-layers-diff-1.json
docker inspect $2 | jq '.[].RootFS.Layers' > /tmp/${USER}-$$-docker-layers-diff-2.json
diff -y --color /tmp/${USER}-$$-docker-layers-diff-1.json /tmp/${USER}-$$-docker-layers-diff-2.json
rm -f /tmp/${USER}-$$-docker-layers-diff-1.json /tmp/${USER}-$$-docker-layers-diff-2.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment