shell-host/docker/docker/02-docker.lib

17 lines
665 B
Bash

#!/bin/bash
command -v docker >/dev/null 2>&1 || return
docker_terminal () {
docker exec -it $1 /bin/sh
}
docker_latest_image() {
image=$1
major=${2:-1}
tokenUri="https://auth.docker.io/token"
data=("service=registry.docker.io" "scope=repository:$image:pull")
token="$(curl --silent --get --data-urlencode ${data[0]} --data-urlencode ${data[1]} $tokenUri | jq --raw-output '.token')"
listUri="https://registry-1.docker.io/v2/$image/tags/list"
curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $token" $listUri \
| jq --raw-output ".tags[] | select(. | startswith(\"$major.\"))" | sort -V | sed -n \$p
}