0Pricing
MLOps Academy · درس

تصغير الصور باستخدام عمليات البناء متعددة المراحل

قلّل حجم الصورة بفصل طبقات البناء عن طبقات التشغيل.

تصغير الصور باستخدام عمليات البناء متعددة المراحل درس مجاني في MLOps Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في MLOps Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة MLOps Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Big Images Hurt

A bloated image is slow to push, pull, and start, and it carries more to patch. Multi-stage builds ship only what you actually need.

The Core Idea

You use one stage to build and a second clean stage to run. Build tools stay behind, so the final image stays small.

Name a Build Stage

Add AS builder to a FROM line to name a stage. You can reference that name later to pull files out of it.

FROM python:3.11 AS builder

Install Into the Builder

In the builder, install dependencies to a known prefix. The --user flag drops everything neatly under one copyable folder.

RUN pip install --user --no-cache-dir -r requirements.txt

Start the Runtime Stage

Open a fresh, slim stage for what actually runs. It has none of the compilers or caches the builder needed.

FROM python:3.11-slim

Copy Only the Artifacts

Use COPY --from=builder to lift just the installed packages into the runtime stage. The heavy build layer is left behind.

COPY --from=builder /root/.local /root/.local

Bring in Your Code

Copy your application source into the slim stage too. Now the final image holds your code plus only its runtime dependencies.

COPY . /app

Fix the Path

User-installed packages live under .local, so add that to PATH. Otherwise the runtime cannot find your installed commands.

ENV PATH=/root/.local/bin:$PATH

Only Last Stage Ships

Docker keeps only the final stage in your image. Everything in earlier stages is discarded unless you explicitly copy it.

Try Distroless

For the smallest, safest result, run on a distroless base with no shell or package manager. Less surface means fewer things to exploit.

Measure the Win

Check the size drop with docker images. Slimming from over a gigabyte to a couple hundred megabytes is common and worth it.

docker images model-api

Quick Check

Let us check what a multi-stage build keeps.

Recap

You split build from runtime, copied just the artifacts with COPY --from, fixed PATH, and shrank the image. Lean and fast. ✅

الأسئلة الشائعة

هل درس «تصغير الصور باستخدام عمليات البناء متعددة المراحل» مجاني؟

نعم — نص درس «تصغير الصور باستخدام عمليات البناء متعددة المراحل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة MLOps Academy، انتقل إلى CoddyKit PRO. تتضمن دورة MLOps Academy 4 دروس في المجموع.

ماذا ستتعلم في «تصغير الصور باستخدام عمليات البناء متعددة المراحل»؟

قلّل حجم الصورة بفصل طبقات البناء عن طبقات التشغيل. تتمرن على MLOps Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ MLOps Academy؟

لا تُشترط خبرة سابقة. MLOps Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «تصغير الصور باستخدام عمليات البناء متعددة المراحل»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس MLOps Academy هذا؟

نعم. كل درس في MLOps Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. كتابة Dockerfile لواجهة برمجة نموذج
  2. تصغير الصور باستخدام عمليات البناء متعددة المراحل
  3. تمرير الإعدادات عبر متغيرات البيئة
  4. تشغيل الحاوية واختبارها محلياً
← العودة إلى MLOps Academy