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:28The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52The 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:44How to Fix the "tsx: not found" Error During Vue Vite Builds in Docker
Duration: 00:00 | DP | 2026-01-10 08:10:19Mastering PHP Switch: How to Handle Multiple Conditions for a Single Case
Duration: 00:00 | DP | 2025-11-17 09:35:40Git Pull Failed? Easily Fix the 'Your local changes would be overwritten' Error
Duration: 00:00 | DP | 2025-12-25 20:40:00The Ultimate Guide to Docker Cron Jobs: Effortlessly Scheduling PHP Tasks in Containers from the Host
Duration: 00:00 | DP | 2025-12-29 10:30:50From Phantom Conflicts to Docker Permissions: A Deep Dive into Debugging an Infinite Loop in a Git Hook for an AI Assistant
Duration: 00:00 | DP | 2025-11-09 16:39:00How to Add Port Mappings to a Running Docker Container: 3 Proven Methods
Duration: 00:00 | DP | 2026-02-05 10:16:12Recommended
The Git Undo Button: How to Completely Revert and Delete Your Last Commit
00:00 | 134Accidentally committed the wrong code or a mislead...
NVM/Node Command Not Found in New macOS Terminals? A Two-Step Permanent Fix!
00:00 | 142A comprehensive guide to fixing the common "comman...
The Art of MySQL Index Order: A Deep Dive from Composite Indexes to the Query Optimizer
00:00 | 129This article provides a deep dive into the philoso...
Frontend Performance Boost: Fixing URL Filter Logic to Eliminate Unnecessary Page Reloads
00:00 | 87Unnecessary page refreshes triggered by filter fun...