Fixing 'Unable to locate package openjdk-17-jdk' in PHP 8 Docker (Debian Trixie)
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
Resolving PHP "could not find driver" Error: Ultimate Guide to Missing PDO Database Drivers
Duration: 00:00 | DP | 2026-07-04 08:03:00Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00Complete Guide to Installing and Configuring Git Server on Synology NAS: Basic to Advanced
Duration: 00:00 | DP | 2026-07-16 20:39:02Why Do .smbdelete Hidden Files Appear After Deleting on Mac SMB Shares? Causes & Ultimate Solutions
Duration: 00:00 | DP | 2026-06-27 19:10:00Complete Guide to Setting Docker Container Timezone to UTC+8 (Asia/Shanghai)
Duration: 00:00 | DP | 2026-06-30 20:43:30Ultimate Guide to Fixing Nginx [warn] conflicting server name Warning
Duration: 00:00 | DP | 2026-07-21 09:02:28Docker Compose Advanced: Configuring Static IPs and Cross-Container SOCKS5 Proxies
Duration: 00:00 | DP | 2026-07-26 09:28:30Nginx Reverse Proxy Guide: Elegantly Routing Specific Subdirectories to Docker Containers
Duration: 00:00 | DP | 2026-07-26 21:31:06DevOps Practice: How to Safely Clear Logs of a Running Docker Container?
Duration: 00:00 | DP | 2026-07-27 09:33:42Ultimate Guide to Setting Up Proxies on CentOS: Global Configuration and Troubleshooting
Duration: 00:00 | DP | 2026-07-27 21:36:19Practical Guide: Translating Complex Docker Compose to Docker Run Commands
Duration: 00:00 | DP | 2026-07-29 09:44:07The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52Cron Job Failing? The Ultimate Guide to Fixing 'docker: command not found'
Duration: 00:00 | DP | 2026-08-01 09:59:44The Ultimate 'Connection Refused' Guide: A PHP PDO & Docker Debugging Saga of a Forgotten Port
Duration: 00:00 | DP | 2025-12-03 09:03:20Solving the MySQL Docker "Permission Denied" Error on Synology NAS: A Step-by-Step Guide
Duration: 00:00 | DP | 2025-12-03 21:19:10How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Docker Exec Mastery: The Right Way to Run Commands in Containers
Duration: 00:00 | DP | 2026-01-08 08:07:44Recommended
Unlock Your IDE's Full Potential: A Deep Dive into PHPDoc for Flawless PHP Autocompletion
00:00 | 134This article provides a deep dive into the core ro...
The SQL LIKE Underscore Trap: How to Correctly Match a Literal '_'?
00:00 | 139Why does a SQL query with `LIKE 't_%'` incorrectly...
Solved: Docker's 'invalid reference format' Error - Why You Shouldn't Use a URL for Your Image
00:00 | 26Encountering the `docker: invalid reference format...
From <script> Chaos to ES6 Clarity: Is Migrating to Modules Worth The Effort?
00:00 | 171Still manually managing the loading order of <scri...