This is how I do get all version tags of an image in a custom docker registry:
r=`curl -sS "$registry/v2/" \
-o /dev/null \
-w '%{http_code}:%header{www-authenticate}'`
http_code=`echo "$r" | cut -d: -f1`
curl_args=(-sS -H 'Accept: application/vnd.docker.distribution.manifest.v2+json')
curl_args+=(-u "$creds")
tags=`curl "${curl_args[@]}" "$registry/v2/$image/tags/list" | jq -r .tags[] | sort -V`
The result could be something like:
1.0.0
1.1.2
1.2.0
1.2.1
1.0.1
1.1.0
1.1.1
1.2.1
Now I just want to get all tags except the newest three and if there are less than three tags, the result should be empty. So in this example I need to get
1.0.0
1.0.1
1.1.0
1.1.1
1.1.2
I tried to use unset $tags[-3]
, but I think I do not get an array returned by the last curl call. So is sort -V
working at all with this syntax?