Depricated code in Dockerfile for Java language-specific guide

Ouverte Adaptée aux débutants
#26,484 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Documentation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
docker, docker-compose, java, spring-boot

Piste de recherche

Commencez par le guide Java à l’adresse https://docs.docker.com/guides/java/ et examinez son Dockerfile, en particulier les étapes d’extraction et d’exécution. Comparez les commandes avec les instructions liées sur les Dockerfile pour Spring Boot et vérifiez le Dockerfile joint. Le travail est terminé lorsque le guide permet de construire l’image et de démarrer le conteneur avec la commande documentée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Markdown
Étoiles
4.7k
Forks
8.5k
Merge moyen
2 j 9 h
PR mergées (30 j)
134

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de docker/docs

Toutes les issues de docker/docs

Issues similaires

Plus d'issues DevOps

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.