Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
ProGet API to get the operating systems of all Docker images
-
Hi All,
I used the API (/api/json/DockerImages_GetTags) to get all Docker images and their properties. However, I could not find any API that can get the Docker images' OSs (Windows/ Linux). Can you provide me with the API that get the OSs of docker images?
-
DockerImages_GetTags
is part of the Native API, which is basically just a wrapper around the SQL ProGet database. That's fine to use, but you can also use the Docker API to list tags as follows:curl -X GET https://proget-url/v2/feedName/repositoryName/tags/list
The Docker API will show you tags that come through a connector, where as the Native API is will only be local tags.
The Docker API does not provide a way to directly retrieve the operating system information of Docker images. However, you can infer the operating system information by examining the contents of the Docker image itself or by using external tools and scripts.
Here's an example in Python of how to do that:
import docker def get_os_of_image(image_name, tag): client = docker.from_env() image = client.images.get(f"{image_name}:{tag}") os_info = image.attrs['Os'] return os_info # Example usage os_info = get_os_of_image('my-image', 'latest') print(f"Operating System: {os_info}")
Alternatively, you can also inspect the image layers directly. Docker image layers contain files from the image's filesystem, and you can look for specific files or patterns that are indicative of the operating system.
Best,
Dean
-
@dean-houston said in ProGet API to get the operating systems of all Docker images:
curl -X GET https://proget-url/v2/feedName/repositoryName/tags/list
Thank you for your help!
I passed X-ApiKey to the API Key Authorization in Postman, but I got the following error:
"errors": [ { "code": "UNAUTHORIZED", "message": "Anonymous is not permitted to perform the Feeds_ViewFeed task for the current scope.", ... }
]
What should I pass for authorization?
-
Due to some reasons I don't fully understand, authenticating to the Docker API requires using a Bearer authentication token
Authorization: Bearer {token}
Here is an example for how to get that token:
function GetDockerToken() { param ( [string] $packageName = $(throw "-packageName is required. This is the namespace and image name. For example: library/my-container-image"), [string] $feed = $(throw "-feed is required"), [string] $actionToAuthorize = $(throw "-action is required. This is the docker action to be authorized (pull, push, delete, etc)"), [string] $apiKey = $(throw "-apiKey is required"), [string] $progetBaseUrl = $(throw "-progetBaseUrl is required. "), [string] $service ) if ($service -eq "") { # This expects that $progetBaseUrl is prepended with "https://" If you are using "http://" then change 8 to 7 below. $service = $progetBaseUrl.SubString(8,$progetBaseUrl.Length-8) } $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "api","$apiKey"))) $response = Invoke-WebRequest -Uri "$progetBaseUrl/v2/_auth?service=$service&scope=repository`:$feed/$packageName`:$actionToAuthorize" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} if ($response.StatusDescription -eq "OK") { $token = ($response.Content | ConvertFrom-Json).token $token } }
I know we plan to document all this better some day, for now you can find the Semantic Versioning for Containers page.
Dean