获取debian-slim的次要版本 [英] Get minor version of debian-slim

查看:95
本文介绍了获取debian-slim的次要版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立容器创建管道,我需要能够获得构建容器所基于的debian-slim的主要版本和次要版本.

I am setting up my container creation pipeline and I need to be able to get the major AND minor version of the debian-slim build my container is built on.

我尝试了以下命令:

docker run -it --rm -a stdout --entrypoint lsb_release MyContainer:1.0.0 -a

但这只是返回:

Distributor ID: Debian  
Description:    Debian GNU/Linux 10 (buster)   
Release:        10  
Codename:       buster  

未列出次要版本.

我也尝试过:

docker run -it --rm -a stdout --entrypoint cat MyContainer:1.0.0 "/etc/os-release"

但是只能输出:


PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

再次

,没有次要版本.

again, no minor version.

是否有获取次要版本的方法?容器OS甚至不知道其完整版本号吗?

推荐答案

事实上,在Debian9的旧时代,您可以使用 lsb_release -a 来获取次要版本:

In fact, in the old days on Debian9, you could use lsb_release -a to get the minor version as next:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 9.5 (stretch)
Release:        9.5
Codename:       stretch

您可能知道,/usr/bin/lsb_release 最终将调用/usr/lib/python3/dist-packages/lsb_release.py ,为此的实现差异debian9&之间的脚本debian10有所作为.

You may know, /usr/bin/lsb_release will finally call /usr/lib/python3/dist-packages/lsb_release.py, the realization diff for this script between debian9 & debian10 made the difference.

  • 在debian9中,它是下一个:

  • In debian9, it's next:

def get_distro_information():
    lsbinfo = get_lsb_information()
    # OS is only used inside guess_debian_release anyway
    for key in ('ID', 'RELEASE', 'CODENAME', 'DESCRIPTION',):
        if key not in lsbinfo:
            distinfo = guess_debian_release()
            distinfo.update(lsbinfo)
            return distinfo
    else:
        return lsbinfo

get_lsb_release 将获取/etc/lsb-release 的内容,但是debian版本中没有文件,因此不返回任何文件.然后,该过程必须回退到 guess_debian_release ,它将从/etc/debian_version 中获取内容,因此您会获得次要版本.

get_lsb_release will fetch the contents of /etc/lsb-release, but there is no file in debian release, so it returns none. Then the procedure have to fallback to guess_debian_release which will fetch the contents from /etc/debian_version, so you get the minor version.

在debian10中,它是下一个:

In debian10, it's next:

def get_distro_information():
    lsbinfo = get_os_release()
    # OS is only used inside guess_debian_release anyway
    for key in ('ID', 'RELEASE', 'CODENAME', 'DESCRIPTION',):
        if key not in lsbinfo:
            distinfo = guess_debian_release()
            distinfo.update(lsbinfo)
            return distinfo
        else:
            return lsbinfo

get_os_release 将获取/usr/lib/os-release 的内容,下一步是:

get_os_release will fetch the contents of /usr/lib/os-release, the contens is next:

PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

因为它已经获得了版本,所以不再回退到 guess_debian_release ,因此您没有获得次要版本.我猜想的好处是,如果不使用 guess_debian_release ,它将使用较少的IO操作,但在我看来,这确实是无数的(也许还需要一些硬编码才能猜到).

As it already get the version, so nolonger fallback to guess_debian_release, so you did not get the minor version. The advantage I guess is if not use guess_debian_release, it will use less IO operation, but in my opinion, really countless (Also maybe some hardcoding for guess).

最后,作为一种解决方法,在debian10上,您可以使用next获得与debian 9相同的行为:

Finally, as a workaround, on debian10, you could use next to get the same behavior as debian 9:

$ LSB_OS_RELEASE="" lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 10.4 (buster)
Release:        10.4
Codename:       buster

这篇关于获取debian-slim的次要版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆