Debian or Fedora? A Quick Guide to Identify Your Docker PHP Container's Base Linux Distro

Published: 2026-03-06
Author: DP
Views: 0
Category: Docker
Content
## The Problem In daily development and operations, we frequently use official or third-party Docker images, such as `php:8-fpm`. When you need to get inside a container to install debugging tools (like `vim`, `curl`) or system dependencies for compiling PHP extensions, a common question arises: What is the underlying Linux distribution of this container? Is it based on Debian/Ubuntu, or Fedora/RHEL? Using the wrong package manager (e.g., running `yum` on a Debian system) will result in command failures and wasted time. This article from the **wiki.lib00.com** team will detail several methods for identification, from best practices to alternative solutions, helping you quickly determine your container's "lineage." --- ## The Best Practice: Check the `/etc/os-release` File Almost all modern Linux distributions include the `/etc/os-release` file. It provides a standardized way to retrieve operating system identification data. This is the most recommended and reliable method. **Here are the steps:** 1. First, find the name or ID of your running PHP container using the `docker ps` command. ```bash docker ps ``` 2. Next, use the `docker exec` command to run `cat` inside the container and view the contents of the `/etc/os-release` file. Replace `<container_name_or_id>` with your actual container identifier. ```bash # Example using a container from the wiki.lib00 project docker exec my-php-container-lib00 cat /etc/os-release ``` **How to Interpret the Output:** * **Debian/Ubuntu Family:** The output will contain `ID=debian` or `ID=ubuntu`. The presence of `ID_LIKE=debian` is also a strong indicator. ```text PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" ``` * **Fedora/RHEL Family (including CentOS):** The output will contain `ID=fedora`, `ID=rhel`, or `ID="centos"`. `ID_LIKE="rhel fedora"` is also a key piece of information. ```text NAME="Red Hat Enterprise Linux" VERSION="8.5 (Ootpa)" ID="rhel" ID_LIKE="fedora" VERSION_ID="8.5" PRETTY_NAME="Red Hat Enterprise Linux 8.5 (Ootpa)" ``` --- ## Alternative Methods In some minimal containers (like certain custom `distroless` images), the `/etc/os-release` file might not exist. In such cases, you can try the following methods. ### 1. Check for Distribution-Specific Files Different Linux distribution families have their own legacy identification files. * **Debian/Ubuntu:** Check if the `/etc/debian_version` file exists. ```bash docker exec <container_name_or_id> cat /etc/debian_version ``` * **Fedora/RHEL:** Check if the `/etc/redhat-release` file exists. ```bash docker exec <container_name_or_id> cat /etc/redhat-release ``` Usually, only one of these files will exist, directly revealing its distribution family. ### 2. Identify by Package Manager This is a very practical method, as your ultimate goal is often to use the package manager. Use the `which` command to check which package management tool is in the system's `PATH`. * **Debian/Ubuntu (APT-based):** ```bash # Check if the apt or dpkg command exists docker exec <container_name_or_id> which apt # Output: /usr/bin/apt ``` * **Fedora/RHEL (DNF/YUM-based):** ```bash # Check if dnf, yum, or rpm command exists docker exec <container_name_or_id> which dnf # Output: /usr/bin/dnf ``` Whichever command successfully returns a path indicates which family the container belongs to. --- ## Pro Tip by DP@lib00 The vast majority of official `php:fpm` Docker images (e.g., `php:8.1-fpm`, `php:8.2-fpm`) are built on **Debian**. Therefore, unless you are using a version explicitly tagged as `alpine` (like `php:8.2-fpm-alpine`) or a custom-built image from your organization (e.g., the lib00 team), you can almost certainly assume it's a Debian-based system. In these images, you should use `apt-get` to manage packages. --- ## Conclusion Identifying the underlying Linux distribution of a Docker container is a fundamental skill in container management. The most reliable method is to inspect the `/etc/os-release` file. If that fails, checking for distribution-specific files or the presence of a package manager are effective alternatives. Mastering these techniques will make you more proficient in any containerized environment.
Related Contents