Verify the version of ubuntu running in a Docker container
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Knowing the exact Ubuntu version inside a Docker container matters for package compatibility, security patching, and debugging. Docker images are often tagged with version labels like ubuntu:22.04, but the actual OS version inside the container can differ from the tag if the image was built from a custom base. There are several commands to check the version — from inside a running container, from outside using docker exec, or by inspecting the image without running it.
Method 1: cat /etc/os-release
The most reliable method. This file exists on all modern Ubuntu images and contains structured version data:
Output:
The key fields are VERSION_ID (e.g., 22.04) and VERSION_CODENAME (e.g., jammy).
Method 2: lsb_release -a
The lsb_release command gives a clean summary, but it is not installed in minimal Docker images:
Output:
If the command is not found, install it:
For minimal images, cat /etc/os-release is preferred since it requires no extra packages.
Method 3: cat /etc/lsb-release
A simpler file that exists on most Ubuntu images:
Output:
Method 4: /etc/issue
A short one-liner that shows the version:
Output:
The \n and \l are escape codes for hostname and terminal line — they appear literally in Docker since there is no login session.
Method 5: Without Running the Container
You can inspect the image metadata or run a throwaway container:
Note that ubuntu:latest may point to the same image as a specific version tag.
Method 6: From a Dockerfile
During a build, you can verify the base image version:
Scripting Version Checks
Extract specific fields for use in scripts or CI pipelines:
Ubuntu Version Reference
| Version | Codename | LTS | End of Support |
| 24.04 | Noble Numbat | Yes | April 2034 |
| 22.04 | Jammy Jellyfish | Yes | April 2032 |
| 20.04 | Focal Fossa | Yes | April 2030 |
| 18.04 | Bionic Beaver | Yes | April 2028 (ESM) |
LTS releases receive five years of standard support and up to ten years with Extended Security Maintenance (ESM).
Common Pitfalls
- Trusting the image tag:
docker pull ubuntu:latestdoes not always mean the latest LTS. Thelatesttag is set by the image maintainer and may not update immediately. Always verify inside the container. - Missing
lsb_releasein minimal images: Docker Ubuntu images are stripped down. Use/etc/os-releaseinstead of installinglsb-releasejust to check the version. - Confusing host and container versions:
cat /etc/os-releaseon the host shows the host OS, not the container. Always usedocker execto run the command inside the container. - Assuming all Ubuntu-based images are Ubuntu: Images built
FROM ubuntu:22.04may install packages that change/etc/issueor add custom/etc/os-releaseentries. Check the Dockerfile or image history withdocker history <image>. - Alpine or Debian images mistaken for Ubuntu: Some Docker images use Debian or Alpine as the base.
/etc/os-releasewill show the actual distribution. CheckID=ubuntuto confirm it is actually Ubuntu.
Summary
/etc/os-releaseis the most reliable method — works on all Ubuntu Docker images without extra packageslsb_release -agives a clean summary but requires thelsb-releasepackage- Use
docker exec <container> cat /etc/os-releaseto check from outside the container - Use
docker run --rm <image> cat /etc/os-releaseto check an image without starting a persistent container - Do not trust image tags blindly — always verify the actual version inside the container
- Extract specific fields with
grepandcutfor scripting and CI pipelines

