Skip to content

Instantly share code, notes, and snippets.

@rajiteh
Created July 26, 2017 04:14
Show Gist options
  • Save rajiteh/7b9f655cc400ba49d6b2bca78bd1469b to your computer and use it in GitHub Desktop.
Save rajiteh/7b9f655cc400ba49d6b2bca78bd1469b to your computer and use it in GitHub Desktop.
Ghetto Docker Update
#!/bin/sh
RUNNING="$(docker ps --format "{{ .ID }}" | xargs docker inspect --format "{{ .Image }}" | xargs docker inspect --format "{{ .Id }} {{ .RepoTags }}")"
AVAILABLE="$(docker images --format "{{ .ID }} [{{ .Repository }}:{{ .Tag }}]" --no-trunc)"
NEEDS_UPDATE=0
echo "${RUNNING}" | while read line; do
current_id=$(echo "${line}" | awk '{print $1}')
current_tag=$(echo "${line}" | awk '{print $2}')
updated_id=$(echo "${AVAILABLE}" | grep -F "${current_tag}" | awk '{print $1}')
if [ "$current_id" != "$updated_id" ]; then
echo "Update required for ${current_tag}"
NEEDS_UPDATE=1
fi
done
exit ${NEEDS_UPDATE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment