Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Created December 1, 2023 07:37
Show Gist options
  • Save codepunkt/c6d3fad41e708e26f838a2c0d004fbec to your computer and use it in GitHub Desktop.
Save codepunkt/c6d3fad41e708e26f838a2c0d004fbec to your computer and use it in GitHub Desktop.
Check available platforms for docker image:tag
# to be pasted into .bashrc or .zshrc
docker_image_platform() {
if [ -z "$1" ]; then
echo "Error: Please provide a Docker image name with version."
return 1
fi
local image="$1"
local version=$(docker --version | awk '{print $3}' | tr -d ',')
if ! command -v jq &> /dev/null; then
echo "Error: jq is not installed."
return 1
fi
local url="http://v${version}/distribution/${image}/json"
local response=$(curl --unix-socket /var/run/docker.sock -s -o /dev/null -w "%{http_code}" "$url")
if [ "$response" -ge 200 ] && [ "$response" -lt 300 ]; then
curl -sS --unix-socket /var/run/docker.sock "$url" | jq '.Platforms'
else
echo "Error: Unable to retrieve information for $image."
return 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment