Lsb_release: 命令在最新的 Ubuntu Docker 容器中找不到

我只是想快速测试一下。所以我运行了一个 docker 容器,我想检查我运行的是哪个版本:

$ docker run -it ubuntu
root@471bdb08b11a:/# lsb_release -a
bash: lsb_release: command not found
root@471bdb08b11a:/#

所以我试着安装它(作为 建议在这里) :

root@471bdb08b11a:/# apt install lsb_release
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package lsb_release
root@471bdb08b11a:/#

有人知道为什么没用吗?

108431 次浏览

It seems lsb_release is not installed.

you can install it via

apt-get update && apt-get install -y lsb-release && apt-get clean all

This error can happen due to uninstalling or upgrading the default python3 program version in ubuntu 16.04

The way to correct this is by reinstalling the original python3 version which comes with ubuntu and relinking again. (in ubuntu 16.04 - the default python3 version is python 3.5

sudo rm /usr/bin/python3
sudo ln -s /usr/bin/python3.5 /usr/bin/python3

lsb_release.py lives in /usr/share/pyshared which to me doesn't look like python3.6 and above is referencing.

I found the following will create a link back from a later Python install to this /usr/share script:

sudo ln -s /usr/share/pyshared/lsb_release.py /usr/lib/python3.9/site-packages/lsb_release.py

While writing Dockerfile we can add lsb-release package - like this

RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install lsb-release -y \
&& apt-get clean all

Assuming OS is Ubuntu.

Just use cat /etc/os-release and that should display the OS details.

Screenshot from debian.

enter image description here

Screenshot from ubuntu.

enter image description here

Screenshot from fedora.

enter image description here

In case one is trying to deal with lsb_release: command not found on fedora or redhat, the package to install is redhat-lsb-core , so sudo dnf install redhat-lsb-core