lsb_release does not exist inside an Ubuntu container
lsb_release: command not foundShort answer
The Ubuntu base image is a minimal install, so the lsb-release package is not in it. Either install it with apt-get update followed by apt-get install, or skip it and read /etc/os-release, which every current release ships and which can be sourced from a shell script.
Fix it fast
1Find out which cause you have
Ask the image for its release file. If this prints, you may not need lsb_release at all.
docker run --rm ubuntu:24.04 cat /etc/os-release2Match what you see, then jump to its fix
What does the error look like?
lsb_release: command not found
Cause 1 of 2
The lsb-release package is not installed in the image
1Check
The Ubuntu image is a minimal install, and the package list is not in it either, so installing needs an update first.
docker run --rm ubuntu:24.04 sh -c 'apt-get update -qq && apt-cache policy lsb-release'2Fix
Install the package in the Dockerfile. Update and install go in one RUN so the package list is never stale.
FROM ubuntu:24.04
RUN apt-get update \
&& apt-get install -y --no-install-recommends lsb-release \
&& rm -rf /var/lib/apt/lists/*3Verify
Build and call the command.
docker build -t lsb-test .
docker run --rm lsb-test lsb_release -aConfirmed by packages.ubuntu.com
Cause 2 of 2
A script only needs the release name or version
1Check
The os-release file holds the same facts: ID, VERSION_ID and VERSION_CODENAME. VERSION_CODENAME is optional and may be missing on some systems.
grep -E '^(ID|VERSION_ID|VERSION_CODENAME)=' /etc/os-release2Fix
Source the file in the script instead of calling the tool. The format allows plain variable assignments, so sourcing it is supported.
. /etc/os-release
echo "$ID $VERSION_ID $VERSION_CODENAME"3Verify
The script prints the values with no extra package installed.
docker run --rm ubuntu:24.04 sh -c '. /etc/os-release; echo $ID $VERSION_ID'Confirmed by man7.org
How do I stop it coming back?
- Prefer /etc/os-release in your own scripts; it needs no package.
- Combine apt-get update and install in the same RUN instruction.
- Do not rely on the minimal image having tools you use on a desktop install.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
ping is missing inside a Docker container
sh: 1: ping: not found
Base images such as ubuntu are minimal, so ping is simply not installed.
2 causes, each with a fixServers
Apache logs SIGWINCH and exits on its own
the httpd container stops although nothing crashed
SIGWINCH is Apache's graceful-stop signal.
2 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
dnf fails to download repo metadata in a CentOS 8 Docker build
The same Dockerfile built fine before 2022
CentOS Linux 8 reached end of life on 31 December 2021 and its content left the mirrors.
2 causes, each with a fixServers
pip install confluent-kafka fails because librdkafka/rdkafka.h is missing
pip stops while building confluent-kafka from source
The error means pip is compiling confluent-kafka from source, and the compiler cannot find the librdkafka C headers.
3 causes, each with a fixServers
Cypress says the npm package is installed but the binary is missing
Cypress binary is missing after npm install in CI or in a Docker build
The npm package is only a launcher.
3 causes, each with a fix