Ubuntu
Docker
Container
Version Check
Linux Commands

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:

bash
1# From inside the container
2cat /etc/os-release
3
4# From outside (running container)
5docker exec my-container cat /etc/os-release

Output:

 
1PRETTY_NAME="Ubuntu 22.04.3 LTS"
2NAME="Ubuntu"
3VERSION_ID="22.04"
4VERSION="22.04.3 LTS (Jammy Jellyfish)"
5VERSION_CODENAME=jammy
6ID=ubuntu
7ID_LIKE=debian
8HOME_URL="https://www.ubuntu.com/"
9SUPPORT_URL="https://help.ubuntu.com/"
10BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
11PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
12UBUNTU_CODENAME=jammy

lsb_release -a (not in minimal images)

lsb_release prints a clean summary, but minimal Docker images don't include it:

bash
docker exec my-container lsb_release -a

Output:

 
1Distributor ID: Ubuntu
2Description:    Ubuntu 22.04.3 LTS
3Release:        22.04
4Codename:       jammy

If the command is not found, install it:

bash
docker exec my-container bash -c "apt-get update && apt-get install -y lsb-release && lsb_release -a"

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:

bash
docker exec my-container cat /etc/lsb-release

Output:

 
1DISTRIB_ID=Ubuntu
2DISTRIB_RELEASE=22.04
3DISTRIB_CODENAME=jammy
4DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"

/etc/issue

A one-line version string:

bash
docker exec my-container cat /etc/issue

Output:

 
Ubuntu 22.04.3 LTS \n \l

\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:

bash
1# Run a temporary container just to check the version
2docker run --rm ubuntu:latest cat /etc/os-release
3
4# Inspect image labels (if the image was built with version labels)
5docker inspect ubuntu:22.04 | grep -i version
6
7# Check the image tag you pulled
8docker images ubuntu
 
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       22.04     6b7dfa7e8fdb   2 weeks ago   77.8MB
ubuntu       latest    6b7dfa7e8fdb   2 weeks ago   77.8MB

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

dockerfile
1FROM ubuntu:22.04
2
3# Print version during build (appears in build output)
4RUN cat /etc/os-release
5
6# Or source it and print a single field
7RUN . /etc/os-release && echo "Building on Ubuntu $VERSION_ID"

Extracting the version in scripts and CI

bash
1# Get just the version number
2docker exec my-container grep VERSION_ID /etc/os-release | cut -d'"' -f2
3# Output: 22.04
4
5# Get the codename
6docker exec my-container grep VERSION_CODENAME /etc/os-release | cut -d= -f2
7# Output: jammy
8
9# Use in a shell variable
10UBUNTU_VERSION=$(docker exec my-container grep VERSION_ID /etc/os-release | cut -d'"' -f2)
11echo "Container is running Ubuntu $UBUNTU_VERSION"

Ubuntu LTS versions and codenames

VersionCodenameLTSEnd of Support
24.04Noble NumbatYesApril 2034
22.04Jammy JellyfishYesApril 2032
20.04Focal FossaYesApril 2030
18.04Bionic BeaverYesApril 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:latest does not always mean the latest LTS. The image maintainer sets the latest tag, and it may not update immediately. Verify inside the container.
  • Installing lsb-release just to check: Docker Ubuntu images are stripped down. Read /etc/os-release instead.
  • Checking the host instead of the container: cat /etc/os-release on the host shows the host OS. Use docker exec to run it inside the container.
  • Assuming Ubuntu-based images are unmodified Ubuntu: images built FROM ubuntu:22.04 may install packages that change /etc/issue or add custom /etc/os-release entries. Check the Dockerfile or the image history with docker history <image>.
  • Mistaking Alpine or Debian images for Ubuntu: some images use Debian or Alpine as the base. /etc/os-release shows the actual distribution, so check for ID=ubuntu.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design