انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهJNR-049-L04

كتابة Dockerfile لتطبيق Spring Boot

  • الدرس 4 من 8
  • Junior
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

write a small, safe image for a Spring Boot app.

الموضوعات المخطط لها

  • A Dockerfile lists the build steps; each instruction makes a layer.
  • Multi-stage build: stage one builds the JAR with the JDK; stage two copies only the JAR into a JRE image, so the final image has no build tools.
  • Run as a non-root user: USER shop.
  • Order instructions so rarely changing layers come first (dependencies before source) for better caching.
  • Use a .dockerignore, pin base image versions, and never put secrets in the image.
  • Verify the current Temurin/JRE image tags before recording.
تفاصيل المخطط المبدئي

عرض عملي

dockerfile
FROM eclipse-temurin:21-jdk AS build
WORKDIR /src
COPY . .
RUN ./mvnw -q package -DskipTests

FROM eclipse-temurin:21-jre
RUN useradd -r shop
USER shop
COPY --from=build /src/target/shop.jar /app/shop.jar
ENTRYPOINT ["java","-jar","/app/shop.jar"]

اختبر فهمك

Why two stages?

أظهر الإجابة

The final image keeps only the JAR and JRE, not the build tools.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.