أساسيات Docker
في هذه الصفحة 8 موضوعات
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
نظرة عامة
الموضوعات
- الصور (Images)
- الحاويات (Containers)
- Dockerfiles
- الأحجام (Volumes)
- الشبكات
تعلّم أولًا
3 ساعة تدريب (تقدير)
مخرجات التعلم
- Explain images, containers, layers, and registries, and how containers differ from VMs.
- Write a multi-stage Dockerfile for a Spring Boot app that runs as a non-root user.
- Use volumes for persistent data and port mapping for access.
- Connect containers on a user-defined network.
- Inspect running containers (
logs,exec,inspect).
الدروس
المختبر والتمارين
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)
| ID | Outcome | Task |
|---|---|---|
| JNR-049-EX01 | 1 | Explain in four sentences the difference between an image and a container, and between a container and a VM. |
| JNR-049-EX02 | 2 | Convert a single-stage Dockerfile (JDK, Maven, source, JAR in one image) into a multi-stage build. |
| JNR-049-EX03 | 2 | Add a non-root user and a .dockerignore; prove with docker exec that the app is not root. |
| JNR-049-EX04 | 3 | Run PostgreSQL with a named volume, insert a row, remove the container, start a new one, and show the row. |
| JNR-049-EX05 | 3 | Map the app to host port 9090 while it listens on 8080 inside. |
| JNR-049-EX06 | 4 | Create a network and make the app reach the database by name. |
| JNR-049-EX07 | 5 | A 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 buildruns Maven; stage twoFROM eclipse-temurin:<jre>doesCOPY --from=buildfor the JAR only. - EX03
RUN useradd -r shopandUSER shop;docker exec shop whoamiprintsshop..dockerignoreliststarget/,.git,.env. - EX04
-v pgdata:/var/lib/postgresql/data; afterdocker rm -fand a newdocker runwith the same volume,selectreturns the row. - EX05
docker run -p 9090:8080 shop:1.0. - EX06
docker network create shop-net; start both with--network shop-net; setSPRING_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.
اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.
الجزء العملي
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).