Skip to content

Instantly share code, notes, and snippets.

@ponfertato
Created September 24, 2025 11:04
Show Gist options
  • Select an option

  • Save ponfertato/30c0393ce707a2e9052fa56e3f504566 to your computer and use it in GitHub Desktop.

Select an option

Save ponfertato/30c0393ce707a2e9052fa56e3f504566 to your computer and use it in GitHub Desktop.
#!/bin/bash
function prompt_command() {
clear
echo "Which command do you want to execute?"
echo "1. Update all images"
echo "2. Update running container images"
echo "3. exit"
read command
}
function update_all_images() {
echo "Checking for updates for all images..."
images=$(docker images --format '{{.Repository}}:{{.Tag}}')
updates=()
for image in $images; do
echo -n "Updating $image... "
# Получаем информацию о последней версии образа
latest_image=$(docker pull $image 2>&1 | grep 'Downloaded newer image' | awk '{print $3}')
if [ "$latest_image" ]; then
updates+=("$image")
echo "Updated!"
else
echo "No updates found."
fi
done
if [ ${#updates[@]} -gt 0 ]; then
echo "Found updates for the following images:"
for update in "${updates[@]}"; do
echo "$update"
done
else
echo "No updates found for any images."
fi
}
function update_running_images() {
echo "Checking for updates for running container images..."
images=$(docker ps --format '{{.Image}}' | sort -u)
updates=()
for image in $images; do
echo -n "Updating $image... "
# Получаем информацию о последней версии образа
latest_image=$(docker pull $image 2>&1 | grep 'Downloaded newer image' | awk '{print $3}')
if [ "$latest_image" ]; then
updates+=("$image")
echo "Updated!"
else
echo "No updates found."
fi
done
if [ ${#updates[@]} -gt 0 ]; then
echo "Found updates for the following running images:"
for update in "${updates[@]}"; do
echo "$update"
done
else
echo "No updates found for running images."
fi
}
prompt_command
while [[ $command -ne 3 ]]; do
case $command in
1)
update_all_images
;;
2)
update_running_images
;;
*)
echo "Invalid option"
;;
esac
prompt_command
done
echo "Exiting."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment