Created
December 1, 2023 07:37
Revisions
-
codepunkt created this gist
Dec 1, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ # 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 }