Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Depricated code in Dockerfile for Java language-specific guide

Aperta Adatta ai principianti
#26,484 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, docker-compose, java, spring-boot

Direzione di ricerca

Parti dalla guida Java all’indirizzo https://docs.docker.com/guides/java/ ed esamina il relativo Dockerfile, in particolare le fasi di estrazione e di esecuzione. Confronta i comandi con le indicazioni collegate sui Dockerfile per Spring Boot e controlla il Dockerfile allegato. Il lavoro è completato quando la guida consente di creare l’immagine e avviare il container con il comando documentato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

status/triage

Dockerfile.txt

Is this a docs issue?
  • My issue is about the documentation content or website
Type of issue

Information is incorrect

Description
1. Depricated -Djarmode in Spring Boot 4.1+ (?3.5+)

Following the guide a command:

docker compose up --build

,throws an error:

=> ERROR [extract 2/2] RUN java -Djarmode=layertools -jar target/app.jar 1.0s
[extract 2/2] RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted:
0.939 Error: Unsupported jarmode 'layertools'
0.939
Dockerfile:53

RUN java -Djarmode=layertools -jar target/app.jar extract --destination target/extracted

2. Copying extracted files into the runtime image’s filesystem root

After solving the first error, ocсurs a second one:

=> CACHED [extract 2/2] RUN java -Djarmode=tools -jar target/app.jar ext 0.0s
=> ERROR [final 3/6] COPY --from=extract build/target/extracted/dependen 0.0s
[final 3/6] COPY --from=extract build/target/extracted/dependencies/ ./:
Dockerfile:83
81 |
82 | # Copy the executable from the "package" stage.
83 | >>> COPY --from=extract build/target/extracted/dependencies/ ./
84 | COPY --from=extract build/target/extracted/spring-boot-loader/ ./
85 | COPY --from=extract build/target/extracted/snapshot-dependencies/ ./

failed to solve: cannot copy to non-directory: /var/lib/docker/buildkit/containerd-overlayfs/cachemounts/buildkit4075886367/lib

3. The container cannot start because of missed JarLauncher

After solving the second error, ocсurs a third one.

✔ Container spring-petclinic-server-1 Created 0.1s
Attaching to server-1
server-1 | Error: Could not find or load main class org.springframework.boot.loader.launch.JarLauncher
server-1 | Caused by: java.lang.ClassNotFoundException: org.springframework.boot.loader.launch.JarLauncher
server-1 exited with code 1

Docker desktop already has a registered container, but cannot start it.

Log: Error: Could not find or load main class org.springframework.boot.loader.launch.JarLauncher

Location

https://docs.docker.com/guides/java/

Suggestion

After all three changes container runs correct.

1. -Djarmode=tools with "--layers" instead of -Djarmode=tlayertools

The problem is use of depricated "layertools"
Remove support for the deprecated layertools jar mode #48568
Spring Boot / Reference / Packaging Spring Boot Applications / Container Images / Dockerfiles

Right line:
RUN java -Djarmode=tools -jar target/app.jar extract --layers --destination target/extracted

2. Add a workdir for application layers

Gordon's solution is from Spring documentation's example code:

The build fails while copying extracted files into the runtime image’s filesystem root, where they can collide with base-image paths such as /lib; I’ll isolate them under /application and retry.

# Line 68
# Keep the application layers separate from operating-system paths in the base image.
WORKDIR /application
3. Change the ENTRYPOINT

Gordon's solution is from Spring documentation's example code.
Change in the last line in Dockerfile.
From:
ENTRYPOINT [ "java", "org.springframework.boot.loader.launch.JarLauncher" ]
To
ENTRYPOINT [ "java", "-jar", "app.jar" ]

And rebuild the image.

P.S. Attached the final dockerfile in .txt format.

Lingua principale
Markdown
Stelle
4.7k
Fork
8.5k
Merge medio
1g 22h
PR unite (30g)
148

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di docker/docs

Tutte le issue di docker/docs

Issue simili

Altre issue su DevOps

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.