Skip to content

Commit 1838848

Browse files
committed
Add Docker best practices system prompt for Java 25
- Created comprehensive XML system prompt (130-java-docker-best-practices.xml) - Covers Docker best practices specific to Java 25 applications - Includes multi-stage builds, JVM optimization, security, and monitoring - Generated corresponding markdown file - Updated SystemPromptsInventory to include new prompt - Updated all project Java versions to Java 25 - Updated Dockerfiles to use Eclipse Temurin Java 25 images
1 parent 32d996d commit 1838848

File tree

2 files changed

+272
-0
lines changed

2 files changed

+272
-0
lines changed

130-java-docker-best-practices.md

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
Docker Best Practices for Java 25 Applications
2+
3+
Comprehensive guidelines for containerizing Java 25 applications using Docker, focusing on performance optimization, security enhancements, and efficient resource utilization.
4+
5+
6+
7+
8+
Use Appropriate Base Images
9+
10+
Select the most suitable base image for your Java 25 application, considering size, security, and compatibility requirements.
11+
12+
13+
Use `eclipse-temurin:25-jre-alpine` for minimal production images
14+
Use `eclipse-temurin:25-jdk-alpine` only when JDK tools are required at runtime
15+
Prefer Alpine Linux variants for smaller image sizes
16+
Use specific version tags instead of `latest` for reproducible builds
17+
18+
19+
### Example :
20+
21+
Title:
22+
Description:
23+
24+
25+
26+
27+
Implement Multi-Stage Builds
28+
29+
Separate the build environment from the runtime environment to create lean, secure final images by excluding unnecessary build tools and dependencies.
30+
31+
32+
Use a build stage with JDK for compilation
33+
Use a runtime stage with JRE for execution
34+
Copy only necessary artifacts between stages
35+
Minimize the number of layers in the final image
36+
37+
38+
### Example :
39+
40+
Title:
41+
Description:
42+
43+
44+
45+
46+
Optimize JVM Configuration for Containers
47+
48+
Configure the JVM to work efficiently within container resource constraints, taking advantage of Java 25's container awareness features.
49+
50+
51+
Use `-XX:+UseContainerSupport` to enable container awareness (enabled by default in Java 25)
52+
Set appropriate heap size using `-Xms` and `-Xmx` based on container memory limits
53+
Use `-XX:+UseG1GC` for better performance in containerized environments
54+
Enable JVM ergonomics with `-XX:+UnlockExperimentalVMOptions` for Java 25 features
55+
Use `-XX:+ExitOnOutOfMemoryError` to ensure container restart on OOM
56+
57+
58+
### Example :
59+
60+
Title:
61+
Description:
62+
63+
64+
65+
66+
Implement Security Best Practices
67+
68+
Enhance container security by following the principle of least privilege and implementing defense-in-depth strategies.
69+
70+
71+
Create and use a non-root user for running the application
72+
Use read-only root filesystem when possible
73+
Minimize the attack surface by removing unnecessary packages
74+
Scan images for vulnerabilities regularly
75+
Use secrets management for sensitive data
76+
77+
78+
### Example :
79+
80+
Title:
81+
Description:
82+
83+
84+
85+
86+
Optimize Image Layers and Caching
87+
88+
Structure Dockerfile commands to maximize Docker layer caching and minimize image size.
89+
90+
91+
Order commands from least to most frequently changing
92+
Copy dependency files before source code to leverage cache
93+
Combine related RUN commands to reduce layers
94+
Use `.dockerignore` to exclude unnecessary files
95+
Clean up package caches and temporary files in the same layer
96+
97+
98+
### Example :
99+
100+
Title:
101+
Description:
102+
103+
104+
105+
106+
Configure Health Checks and Monitoring
107+
108+
Implement comprehensive health checking and monitoring to ensure application reliability and observability.
109+
110+
111+
Define Docker health checks for container orchestration
112+
Implement application health endpoints
113+
Configure proper logging to stdout/stderr
114+
Use structured logging formats (JSON) for better parsing
115+
Include JVM metrics and garbage collection monitoring
116+
117+
118+
### Example :
119+
120+
Title:
121+
Description:
122+
123+
124+
125+
126+
Manage Configuration and Secrets
127+
128+
Externalize configuration and handle secrets securely to support different deployment environments.
129+
130+
131+
Use environment variables for configuration
132+
Support configuration files mounted as volumes
133+
Never embed secrets in Docker images
134+
Use Docker secrets or external secret management
135+
Implement configuration validation at startup
136+
137+
138+
### Example :
139+
140+
Title:
141+
Description:
142+
143+
144+
145+
146+
Optimize for Different Deployment Scenarios
147+
148+
Create flexible Docker configurations that work well across development, testing, and production environments.
149+
150+
151+
Use build arguments for environment-specific customization
152+
Support both standalone and orchestrated deployments
153+
Implement graceful shutdown handling
154+
Configure appropriate resource limits and requests
155+
Use init systems for proper signal handling in containers
156+
157+
158+
### Example :
159+
160+
Title:
161+
Description:
162+
163+
164+
165+
166+
Leverage Java 25 Specific Features
167+
168+
Take advantage of Java 25's latest features and improvements for better container performance and developer experience.
169+
170+
171+
Use Virtual Threads for improved scalability in I/O-intensive applications
172+
Leverage Pattern Matching and Switch Expressions for cleaner code
173+
Use Record Classes for data transfer objects
174+
Take advantage of improved garbage collection algorithms
175+
Use Text Blocks for embedded configuration or SQL
176+
177+
178+
### Example :
179+
180+
Title:
181+
Description:
182+
183+
184+
185+
186+
Implement Efficient Development Workflow
187+
188+
Create Docker configurations that support efficient development cycles and debugging capabilities.
189+
190+
191+
Use Docker Compose for local development environments
192+
Implement hot-reload capabilities for development
193+
Support remote debugging configurations
194+
Create separate profiles for development and production
195+
Use volume mounts for rapid iteration during development
196+
197+
198+
### Example :
199+
200+
Title:
201+
Description:
202+
203+
204+
205+
206+
207+
208+
Using Root User in Production
209+
Running applications as root user increases security risks
210+
211+
### Example :
212+
213+
Title:
214+
Description:
215+
216+
217+
218+
219+
Installing Unnecessary Packages
220+
Including development tools and unnecessary packages in production images
221+
222+
### Example :
223+
224+
Title:
225+
Description:
226+
227+
228+
229+
230+
Hardcoding Configuration
231+
Embedding environment-specific configuration in Docker images
232+
233+
### Example :
234+
235+
Title:
236+
Description:
237+
238+
239+
240+
241+
Ignoring JVM Container Settings
242+
Not configuring JVM for container resource limits
243+
244+
### Example :
245+
246+
Title:
247+
Description:
248+
249+
250+
251+
252+
Using Latest Tags in Production
253+
Using unstable or latest tags for base images in production
254+
255+
### Example :
256+
257+
Title:
258+
Description:
259+
260+
261+
262+
263+
264+
Use multi-stage builds with appropriate base images
265+
Configure JVM for container environments
266+
Implement security best practices with non-root users
267+
Optimize Docker layers and caching strategies
268+
Configure comprehensive health checks and monitoring
269+
Externalize configuration and manage secrets properly
270+
Leverage Java 25 specific features and improvements
271+
Support efficient development workflows

system-prompts-generator/src/test/java/info/jab/pml/SystemPromptsInventory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static final Stream<String> baseNames() {
2121
"126-java-logging",
2222
"127-java-exception-handling",
2323
"128-java-generics",
24+
"130-java-docker-best-practices",
2425
"131-java-unit-testing",
2526
"141-java-refactoring-with-modern-features",
2627
"142-java-functional-programming",

0 commit comments

Comments
 (0)