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
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:<rant>
Why do they not follow the standard of using lsb_release?</rant>
In fact, in the old days on Debian9, you could use
lsb_release -a
to get the minor version as next: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:
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 toguess_debian_release
which will fetch the contents from/etc/debian_version
, so you get the minor version.In debian10, it’s next:
get_os_release
will fetch the contents of/usr/lib/os-release
, the contens is next: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 useguess_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: