skip to Main Content

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.

I tried the following command:

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

but that just returns:

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

No minor version listed.

I have also tried:

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

but that only outputs:

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.

Is there a way to get the minor version? Does the container OS even know its full version number?

2

Answers


  1. Chosen as BEST ANSWER

    Should have looked a bit harder. (Found it right after posting)

    Debian does it their own way by putting it in the custom, nonstandard, Debian specific file /etc/debian_version found only on Debian Linux:

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

    <rant>Why do they not follow the standard of using lsb_release?</rant>


  2. 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
    

    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.

    • 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 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.

    • 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 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/"
      

      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).

    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search