Install
$ agentstack add skill-linlannet-agent-skills-java-docker ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ● Network access Used
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Java Docker 技能
使用优化的Dockerfile和JVM设置容器化Java应用程序。
概述
此技能涵盖Java的Docker最佳实践,包括多阶段构建、JVM容器设置、安全加固和层优化。
何时使用此技能
当您需要:
- 创建优化的Java Dockerfile
- 为容器配置JVM
- 实施安全最佳实践
- 减小镜像大小
- 设置健康检查
涵盖的主题
Dockerfile优化
- 多阶段构建
- 层缓存策略
- Spring Boot分层JAR
- 依赖缓存
JVM容器设置
- UseContainerSupport
- MaxRAMPercentage
- GC选择
- OOM时退出
安全
- 非root用户
- 只读文件系统
- 漏洞扫描
- 密钥处理
快速参考
# 多阶段优化Dockerfile
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /app
# 缓存依赖
COPY pom.xml .
COPY .mvn .mvn
RUN mvn dependency:go-offline -B
# 构建并提取层
COPY src ./src
RUN mvn package -DskipTests && \
java -Djarmode=layertools -jar target/*.jar extract
# 运行时阶段
FROM eclipse-temurin:21-jre-alpine
# 安全:非root用户
RUN addgroup -S app && adduser -S app -G app
USER app
WORKDIR /app
# 按更改频率顺序复制层
COPY --from=builder /app/dependencies/ ./
COPY --from=builder /app/spring-boot-loader/ ./
COPY --from=builder /app/snapshot-dependencies/ ./
COPY --from=builder /app/application/ ./
# JVM容器设置
ENV JAVA_OPTS="-XX:+UseContainerSupport \
-XX:MaxRAMPercentage=75.0 \
-XX:+ExitOnOutOfMemoryError \
-XX:+UseG1GC"
EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=3s --start-period=30s \
CMD wget -qO- http://localhost:8080/actuator/health/liveness || exit 1
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS org.springframework.boot.loader.launch.JarLauncher"]
JVM容器标志
# 推荐的生产设置
JAVA_OPTS="
-XX:+UseContainerSupport
-XX:MaxRAMPercentage=75.0
-XX:InitialRAMPercentage=50.0
-XX:+ExitOnOutOfMemoryError
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/tmp/heapdump.hprof
-XX:+UseG1GC
-Djava.security.egd=file:/dev/./urandom
"
基础镜像比较
| 镜像 | 大小 | 安全性 | 用例 | |------|------|--------|------| | temurin:21-jre | ~200MB | 良好 | 一般使用 | | temurin:21-jre-alpine | ~100MB | 良好 | 大小优化 | | distroless/java21 | ~80MB | 最佳 | 生产环境 |
安全最佳实践
# 非root用户
RUN addgroup -S app && adduser -S app -G app
USER app
# 只读文件系统
# (在运行时使用 --read-only 配置)
# 使用distroless无shell访问
FROM gcr.io/distroless/java21-debian12
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s \
CMD wget -qO- localhost:8080/actuator/health || exit 1
故障排除
常见问题
| 问题 | 原因 | 解决方案 | |------|------|----------| | OOMKilled | 堆内存 > 限制 | 设置 MaxRAMPercentage | | 启动缓慢 | 镜像过大 | 多阶段构建 | | 权限被拒绝 | 需要root | 修复文件权限 | | 无内存信息 | 旧JVM | 更新到Java 11+ |
调试清单
□ 检查容器内存限制
□ 验证JVM是否看到容器限制
□ 审查健康检查配置
□ 扫描镜像漏洞
□ 测试资源约束
使用
Skill("java-docker")
相关技能
java-maven-gradle- 构建集成java-microservices- K8s部署
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: linlannet
- Source: linlannet/agent-skills
- License: Apache-2.0
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.