Fixing 'Unable to locate package openjdk-17-jdk' in PHP 8 Docker (Debian Trixie)

Published: 2026-07-25
Author: DP
Views: 0
Category: PHP
Content
When configuring a development environment in a PHP 8-based Docker container, developers often encounter issues installing OpenJDK 17. For instance, during the base image build for the `wiki.lib00.com` project, executing `apt-get install -y openjdk-17-jdk` throws the following error: ```text E: Unable to locate package openjdk-17-jdk ``` ## Root Cause Analysis The error logs indicate the system is using **Debian Trixie (Testing)** as its underlying OS. In Debian Trixie, packages are updated rapidly. Older JDK versions like Java 17 are often removed from the testing repository in favor of newer, mainstream releases (like OpenJDK 21). --- ## Solutions (Curated by DP@lib00) Here are the most effective ways to resolve this issue: ### Method 1: Find and Install Available JDKs If you don't strictly need Java 17, you can check which OpenJDK versions are currently supported by the repository: ```bash apt-cache search openjdk- ``` It is highly recommended to install the default JDK or version 21: ```bash # Install the default JDK (automatically points to the most stable version) apt-get install -y default-jdk # Or install OpenJDK 21 directly apt-get install -y openjdk-21-jdk ``` ### Method 2: Change the Base Image (Highly Recommended) If your `wiki.lib00` business logic strictly depends on Java 17, the safest approach is to change the Docker base image to a stable Debian release that explicitly includes `openjdk-17-jdk`. Update your `Dockerfile` base image to Debian 12 (Bookworm) or Debian 11 (Bullseye): * `php:8-bookworm` * `php:8-bullseye` ### Dockerfile Best Practices When writing a Dockerfile, it's best practice to combine `RUN` commands and clear the `apt` cache immediately after installation to reduce the final image size: ```dockerfile # Use Debian 12 as the base FROM php:8-bookworm # Set working directory WORKDIR /var/www/wiki.lib00.com # Update sources, install Java 17, and clean up cache RUN apt-get update && apt-get install -y \ openjdk-17-jdk \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* ```
Related Contents