انتقل إلى المحتوى
أمين أبوزيد
JNR-050

Docker Compose

  • 5 درس
  • 2 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

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

نظرة عامة

الموضوعات

  • بيئة محلية لـ Spring Boot + PostgreSQL

تعلّم أولًا

2 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Define a multi-service local environment (app, PostgreSQL, Keycloak) in compose.yaml.
  2. Use health checks and dependency conditions so services start in a usable order.
  3. Supply configuration through environment files without committing secrets.
  4. Use Spring Boot's Docker Compose support for development.

الدروس

  1. 01ملفات Compose
  2. 02فحوص الصحة وترتيب البدء
  3. 03البيئة والأسرار
  4. 04تكامل Spring Boot مع Compose
  5. 05عرض عملي: بيئة Shop كاملة بأمر واحد

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

Lab

JNR-050-LAB1 · One-command Shop

Outcomes: 1–4 · Time: ~2 h docker compose up starts the whole stack (Shop, PostgreSQL, Keycloak) with seeded data, health checks, and env-file configuration. Write a README. Acceptance: a new teammate runs the stack in under 10 minutes using only the README.

Exercises (assessment: lab check)

IDOutcomeTask
JNR-050-EX011Write a compose.yaml with PostgreSQL (named volume) and the Shop app built from the Dockerfile.
JNR-050-EX021Add Keycloak and expose it on a host port; list which service names reach which.
JNR-050-EX032Add a pg_isready health check and make the app wait with service_healthy.
JNR-050-EX042Explain why the app can still fail even with service_healthy, and what the app should do about it.
JNR-050-EX053Move the database password to .env, add .env.example, and update .gitignore.
JNR-050-EX064Add the Spring Boot Docker Compose dependency and run the app from the IDE without starting Compose manually.
أظهر الحلول
  • EX01 Services db (image: postgres:16, volumes: [pgdata:/var/lib/postgresql/data]) and app (build: ., ports: ["8080:8080"]), plus top-level volumes: pgdata:.
  • EX02 keycloak service with its image and ports; app reaches db:5432 and keycloak:8080 by service name; the browser uses the mapped host port.
  • EX03 healthcheck: test: ["CMD-SHELL","pg_isready -U postgres"] and depends_on: db: condition: service_healthy.
  • EX04 Healthy means ready at that moment; the database can restart later. The app should use connection retries (and a pool that recovers).
  • EX05 POSTGRES_PASSWORD: ${DB_PASSWORD}; .env.example has DB_PASSWORD=change-me; .gitignore lists .env.
  • EX06 Add spring-boot-docker-compose (verify the artifact and Boot version); starting the app launches the stack and wires the datasource.
  • Common mistakes (committed .env, depends_on without health) are checked in the lab.

الاختبار

Outcomes: O1 compose files · O2 health checks · O3 environment and secrets · O4 Spring Boot integration.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1Which file defines a Compose stack?O1
  2. 2Services in one Compose project reach each other by:O1
  3. 3docker compose down -v also removes:O1
  4. 4Plain depends_on waits until the dependency:O2
  5. 5Which makes the app wait for a ready database?O2
  6. 6A Postgres health check commonly uses:O2
  7. 7Which should be committed?O3
  8. 8${DB_PASSWORD} in compose.yaml is filled from:O3
  9. 9Spring Boot's Compose support is meant for:O4
  10. 10What does it do on app start?O4

الجزء العملي

Six exercises JNR-050-EX01 to EX06 plus the lab; the assessment is the lab check. Pass: quiz 8/10, at least five exercises correct, and a teammate starts the stack from the README in under 10 minutes.

أخطاء شائعة

depends_on without health checks; committed .env files.

التقييم

Lab check.

الصلة بالمسار الوظيفي

The capstone's local environment requirement.

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