Check the Ubuntu version running in a Docker container
Codemia Knowledge Hub ·
Run cat /etc/os-release inside the container, or docker exec my-container cat /etc/os-release from the host. The VERSION_ID (for example 22.04) and VERSION_CODENAME (for example jammy) fields give the release. Don't rely on the image tag alone: an image built from a custom base can run a different version than its tag such as ubuntu:22.04 suggests.
/etc/os-release (the reliable method)
This file exists on all modern Ubuntu images and contains structured version data:
Output:
lsb_release -a (not in minimal images)
lsb_release prints a clean summary, but minimal Docker images don't include it:
Output:
If the command is not found, install it:
On minimal images, cat /etc/os-release is the better choice because it needs no extra packages.
/etc/lsb-release
A simpler file present on most Ubuntu images:
Output:
/etc/issue
A one-line version string:
Output:
\n and \l are escape codes for the hostname and terminal line. They show up literally in Docker because there is no login session.
Checking an image without a running container
Run a throwaway container, or inspect the image metadata:
As the matching image IDs show, ubuntu:latest may point to the same image as a specific version tag.
Printing the version during a Docker build
Extracting the version in scripts and CI
Ubuntu LTS versions and codenames
| 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 get five years of standard support and up to ten years with Extended Security Maintenance (ESM).
Ways to get the wrong answer
- Trusting the image tag:
docker pull ubuntu:latestdoes not always mean the latest LTS. The image maintainer sets thelatesttag, and it may not update immediately. Verify inside the container. - Installing
lsb-releasejust to check: Docker Ubuntu images are stripped down. Read/etc/os-releaseinstead. - Checking the host instead of the container:
cat /etc/os-releaseon the host shows the host OS. Usedocker execto run it inside the container. - Assuming Ubuntu-based images are unmodified Ubuntu: images built
FROM ubuntu:22.04may install packages that change/etc/issueor add custom/etc/os-releaseentries. Check the Dockerfile or the image history withdocker history <image>. - Mistaking Alpine or Debian images for Ubuntu: some images use Debian or Alpine as the base.
/etc/os-releaseshows the actual distribution, so check forID=ubuntu.
Related reading
- View Tensorboard on Docker on Google Cloud
- VisualStudio Code PHP executablePath in docker
- Volume mount when setting up Wordpress with docker
- WaitForFirstConsumer PersistentVolumeClaim waiting for first consumer to be created before binding
- What are all the The resourceVersion for the provided watch is too old warnings from event-exporter container?
- What are Docker image layers?
- What are the advantages of running Jenkins in a docker container
- What are the Advantages of using Kubernetes Ingress in Azure AKS
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design GitHub Actions: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.