用于告知容器映像的 OS 版本的命令
Command to tell the OS Version of a container image
我有 .Net Core 3.1.1
的旧 docker 容器映像。我认为它使用 debian-slim 10.2 作为 OS。我希望升级到 .Net Core 3.1.10
图像。我认为使用 debian-slim 10.6.
当我努力制定一个容器计划时,我希望能够轻松地分辨出构建容器映像的 debian-slim 版本。
我可以在容器镜像上 运行 知道它是什么版本的 debian-slim 运行ning 吗?
如果需要示例图像,那么这就是我正在查看的图像:mcr.microsoft.com/dotnet/core/aspnet:3.1.10-buster-slim
。另一个更旧的是 mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim
这条命令似乎给出了版本号,但只有主要版本:
docker run -it --rm -a stdout --entrypoint cat MyContainer:1.0.0 "/etc/os-release"
我将打开一个关于在 debian-slim 容器上查找次要版本号的新问题。
更新:
以下是获取次要版本的方法:
更新:
虽然速度很慢,但如果是 debian 或 ubuntu,此 powershell 脚本将获取容器映像的 linux 发行版和版本号。
function GetOsInfoFromImage
{
param (
[string] $image = $(throw "-image is required")
)
$containerId = docker run --detach --interactive $image
# Get the basic os information from the container and put it in a hash table
$osReleaseInfo = docker exec --interactive --tty $containerId cat "/etc/os-release" | ConvertFrom-StringData
$distribution = $osReleaseInfo.ID
if ($distribution -eq 'debian') {
$version = docker exec --interactive --tty $containerId cat "/etc/debian_version"
# if there are not any man pages then we can be fairly confident that this is a slim build.
# pulled from here: https://github.com/debuerreotype/debuerreotype/blob/master/scripts/.slimify-excludes
$isSlim = (docker exec --interactive --tty $containerId ls "/usr/share/man/").Count > 0
if ($isSlim = $true) {
$distribution = "$($distribution)-slim"
}
} elseif ($distribution -eq 'Ubuntu') {
$version = $osReleaseInfo.VERSION_ID.Trim('"')
}
# cleanup the container we had to make
docker stop $containerId | Out-Null
docker rm $containerId | Out-Null
$finalVersion = "$($distribution.ToLower())_$($version)"
$finalVersion
}
花费很长时间的原因是我必须创建容器实例,然后从映像中删除它。
可以这样使用:
GetOsInfoFromImage mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim
我有 .Net Core 3.1.1
的旧 docker 容器映像。我认为它使用 debian-slim 10.2 作为 OS。我希望升级到 .Net Core 3.1.10
图像。我认为使用 debian-slim 10.6.
当我努力制定一个容器计划时,我希望能够轻松地分辨出构建容器映像的 debian-slim 版本。
我可以在容器镜像上 运行 知道它是什么版本的 debian-slim 运行ning 吗?
如果需要示例图像,那么这就是我正在查看的图像:mcr.microsoft.com/dotnet/core/aspnet:3.1.10-buster-slim
。另一个更旧的是 mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim
这条命令似乎给出了版本号,但只有主要版本:
docker run -it --rm -a stdout --entrypoint cat MyContainer:1.0.0 "/etc/os-release"
我将打开一个关于在 debian-slim 容器上查找次要版本号的新问题。
更新: 以下是获取次要版本的方法:
更新:
虽然速度很慢,但如果是 debian 或 ubuntu,此 powershell 脚本将获取容器映像的 linux 发行版和版本号。
function GetOsInfoFromImage
{
param (
[string] $image = $(throw "-image is required")
)
$containerId = docker run --detach --interactive $image
# Get the basic os information from the container and put it in a hash table
$osReleaseInfo = docker exec --interactive --tty $containerId cat "/etc/os-release" | ConvertFrom-StringData
$distribution = $osReleaseInfo.ID
if ($distribution -eq 'debian') {
$version = docker exec --interactive --tty $containerId cat "/etc/debian_version"
# if there are not any man pages then we can be fairly confident that this is a slim build.
# pulled from here: https://github.com/debuerreotype/debuerreotype/blob/master/scripts/.slimify-excludes
$isSlim = (docker exec --interactive --tty $containerId ls "/usr/share/man/").Count > 0
if ($isSlim = $true) {
$distribution = "$($distribution)-slim"
}
} elseif ($distribution -eq 'Ubuntu') {
$version = $osReleaseInfo.VERSION_ID.Trim('"')
}
# cleanup the container we had to make
docker stop $containerId | Out-Null
docker rm $containerId | Out-Null
$finalVersion = "$($distribution.ToLower())_$($version)"
$finalVersion
}
花费很长时间的原因是我必须创建容器实例,然后从映像中删除它。
可以这样使用:
GetOsInfoFromImage mcr.microsoft.com/dotnet/core/aspnet:3.1.1-buster-slim