Is there any command I can run against a docker registry (public and private) which can return the image operating system? Specifically, I'm looking to distinguish between Linux and Windows images, not between linux distros.
The reason is that we have a docker-based build system today for which we're trying to add support for Windows containers, and LCOW. In theory, Linux builds can take place on either Windows or Linux servers, so we want the tool to have the ability to automatically prepend sudo
on the docker command and --platform
on the pull/run commands (as well as some other things) when appropriate. However, this requires that we automatically detect the OS of the image. I have looked through the docker documentation and was unable to find any support for such a query, but perhaps I missed something.
As I'm writing this, I'm realizing that if the docker client could automatically deduce the OS of an image, they probably would have built this detection into the client rather than introduce the new --platform
argument on all the various docker commands.
Deleted old answer because it was incorrect.
Project Atomic has a tool called "skopeo" that does what you want. Here's a link to the github repository
After you've installed the tool, you should simply be able to do:
$ skopeo inspect docker://docker.io/microsoft/nanoserver | jq '.Os'
"windows"
$ skopeo inspect docker://docker.io/library/ubuntu | jq '.Os'
"linux"
Background:
If you look at the docker image information available under /var/lib/docker/image/<storage-driver>/imagedb/content/sha265/<image-sha>
, you'll find that it looks something like this:
{
"architecture": "amd64",
"config": {
...
},
"container": "6e8eb576ec0f7564a85c0fbd39824e0e91c031aa0019c56c5f992449e88d1142",
"container_config": {
...
},
"created": "2018-03-06T22:17:26.531075062Z",
"docker_version": "17.06.2-ce",
"history": [
...
],
"os": "linux",
"rootfs": {
"type": "layers",
"diff_ids": [
"sha256:a94e0d5a7c404d0e6fa15d8cd4010e69663bd8813b5117fbad71365a73656df9",
"sha256:88888b9b1b5b7bce5db41267e669e6da63ee95736cb904485f96f29be648bfda",
"sha256:52f389ea437ebf419d1c9754d0184b57edb45c951666ee86951d9f6afd26035e",
"sha256:52a7ea2bb533dc2a91614795760a67fb807561e8a588204c4858a300074c082b",
"sha256:db584c622b50c3b8f9b8b94c270cc5fe235e5f23ec4aacea8ce67a8c16e0fbad"
]
}
}
As you can see there's a field available called os
, that says linux
. I suspect if you look at that field for a windows image, it'll say windows
. This is the information available via docker inspect
.
The tricky bit is figuring out which API calls to make to docker.io
to get this information. The docker hub/registry APIs are a little under documented and it's not obvious where this information comes from exactly. Providing this information in a straightforward way seems to be an open bug upstream:
Proposal: inspect image json on a registry
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With