Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

lsb_release does not exist inside an Ubuntu container

Errorlsb_release: command not found

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

  • Applies to Docker Engine 28, Ubuntu 24.04 image, Debian bookworm image
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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-release
  2. 2Match what you see, then jump to its fix

    1. 1lsb_release: command not found, in a RUN step or in an interactive containerThe lsb-release package is not installed in the imageFix
    2. 2The script is yours or a vendor install script, and it calls lsb_release -cs or -rsA script only needs the release name or versionFix

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 -a

Confirmed by packages.ubuntu.com

Did this fix it?

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-release

2Fix

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

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.