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

أساسيات Docker

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

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

نظرة عامة

الموضوعات

  • الصور (Images)
  • الحاويات (Containers)
  • Dockerfiles
  • الأحجام (Volumes)
  • الشبكات

تعلّم أولًا

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

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

  1. Explain images, containers, layers, and registries, and how containers differ from VMs.
  2. Write a multi-stage Dockerfile for a Spring Boot app that runs as a non-root user.
  3. Use volumes for persistent data and port mapping for access.
  4. Connect containers on a user-defined network.
  5. Inspect running containers (logs, exec, inspect).

الدروس

  1. 01لماذا الحاويات
  2. 02الصور والطبقات والسجلات (Registries)
  3. 03تشغيل الحاويات
  4. 04كتابة Dockerfile لتطبيق Spring Boot
  5. 05الأحجام (Volumes) والشبكات
  6. 06تصحيح أخطاء الحاويات
  7. 07عرض عملي: كتابة Dockerfile متعدد المراحل لـ Shop
  8. 08عرض عملي: تصحيح حاوية تتعطل

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

Lab

JNR-049-LAB1 · Containerize Shop

Outcomes: 1–5 · Time: ~3 h Build a multi-stage, non-root Shop image under 300 MB. Run PostgreSQL in a container with a volume and connect Shop through a user-defined network. Acceptance: data survives container removal.

Exercises (assessment: review and improve a poor Dockerfile)

IDOutcomeTask
JNR-049-EX011Explain in four sentences the difference between an image and a container, and between a container and a VM.
JNR-049-EX022Convert a single-stage Dockerfile (JDK, Maven, source, JAR in one image) into a multi-stage build.
JNR-049-EX032Add a non-root user and a .dockerignore; prove with docker exec that the app is not root.
JNR-049-EX043Run PostgreSQL with a named volume, insert a row, remove the container, start a new one, and show the row.
JNR-049-EX053Map the app to host port 9090 while it listens on 8080 inside.
JNR-049-EX064Create a network and make the app reach the database by name.
JNR-049-EX075A container exits immediately. List the three commands you use first and what each shows.
أظهر الحلول
  • EX01 An image is a read-only template of layers; a container is a running instance. A VM has its own OS kernel; a container shares the host kernel and is lighter.
  • EX02 Stage one FROM eclipse-temurin:<jdk> AS build runs Maven; stage two FROM eclipse-temurin:<jre> does COPY --from=build for the JAR only.
  • EX03 RUN useradd -r shop and USER shop; docker exec shop whoami prints shop. .dockerignore lists target/, .git, .env.
  • EX04 -v pgdata:/var/lib/postgresql/data; after docker rm -f and a new docker run with the same volume, select returns the row.
  • EX05 docker run -p 9090:8080 shop:1.0.
  • EX06 docker network create shop-net; start both with --network shop-net; set SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shop.
  • EX07 docker ps -a (exit code), docker logs NAME (error message), docker inspect NAME (env, mounts, ports).
  • Common mistakes (latest, secrets baked into images, building inside the final image) are checked in the assessment review.

الاختبار

Outcomes: O1 concepts · O2 Dockerfile · O3 volumes and ports · O4 networks · O5 inspecting.

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

  1. 1A running instance of an image is a:O1
  2. 2Compared with a VM, a container:O1
  3. 3The main benefit of a multi-stage build:O2
  4. 4To run as non-root in a Dockerfile:O2
  5. 5Which tag practice is best?O2
  6. 6Data that must survive container removal belongs in a:O3
  7. 7-p 9090:8080 means:O3
  8. 8On a user-defined network, the app reaches the database container db using:O4
  9. 9Which shows a container's app output?O5
  10. 10Which opens a shell inside a running container?O5

الجزء العملي

Seven exercises JNR-049-EX01 to EX07 plus the lab; for the assessment, review a poor Dockerfile and submit an improved version. Pass: quiz 8/10, at least five exercises correct, image under 300 MB, and data surviving container removal.

أخطاء شائعة

Building inside the final image; latest tags; secrets baked into images.

التقييم

Review and improve a poor Dockerfile.

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

Kubernetes (MID-057).

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