الحاويات باستخدام Docker وK8s
أتقن استخدام Docker لتحويل التطبيقات إلى حاويات، وKubernetes لتنسيق أعباء العمل الحاوية على نطاق واسع.
الحاويات باستخدام Docker وK8s درس مجاني في System Design Basics for Backend Developers على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في System Design Basics for Backend Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة System Design Basics for Backend Developers 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Welcome to Containerization!
Welcome to this lesson on Containerization with Docker & Kubernetes! In modern cloud environments, packaging and managing applications efficiently is key.
You'll learn how Docker containers bundle your apps and how Kubernetes orchestrates them at scale, making your systems robust and flexible.
What are Containers?
Imagine a tiny, self-contained box for your application. That's a container!
- Isolated: Each container runs its own app and dependencies, separate from others.
- Portable: Works the same way on any machine with a container runtime.
- Lightweight: Shares the host OS kernel, unlike heavier Virtual Machines (VMs).
This consistency solves the "it works on my machine" problem.
Meet Docker: The Container Engine
Docker is the most popular platform for building, sharing, and running containers. It provides the tools to create these isolated environments.
- Docker Engine: The core software that runs and manages containers.
- Docker Image: A read-only template with instructions for creating a container.
- Docker Container: A runnable instance of a Docker image.
Crafting a Dockerfile
A Dockerfile is a plain text file that contains all the commands a user could call on the command line to assemble an image.
It's like a recipe for your container. Here are some common instructions:
FROM: Base image (e.g., Python, Node.js).WORKDIR: Sets the working directory.COPY: Copies files from your project into the image.RUN: Executes commands (e.g., install dependencies).CMD: Default command to run when the container starts.
Simple Python App for Docker
Let's look at a very simple Python application that we could containerize. This is the code that would live inside your Docker container.
Try running this example:
print("Hello from inside the container!")Building & Running with Docker
Once you have a Dockerfile and your application code (like the Python script), you can build an image and run a container.
- Build Image:
docker build -t my-python-app .(-ttags it,.uses current directory for Dockerfile) - Run Container:
docker run my-python-app
This creates and starts a container based on your image, executing the app inside.
Why Kubernetes? Orchestration
Running one container is easy. Running hundreds or thousands across many servers is hard! This is where Kubernetes (K8s) comes in.
K8s is an open-source system for automating deployment, scaling, and management of containerized applications. It acts as an "orchestrator" for your containers.
Kubernetes Pods: The Basics
In Kubernetes, the smallest deployable unit is a Pod. A Pod is an abstraction over containers.
- A Pod represents a single instance of an application.
- It typically contains one (or a few tightly coupled) containers.
- Pods share network and storage resources.
- They are ephemeral: if a Pod dies, K8s creates a new one.
Kubernetes Deployments: Managing Pods
Manually managing Pods is cumbersome. Deployments are a higher-level object in K8s that manage the lifecycle of Pods.
A Deployment allows you to:
- Declare the desired number of replica Pods.
- Perform rolling updates to new versions without downtime.
- Roll back to previous versions if issues arise.
- Ensure that a specified number of Pods are always running.
Test Your Container Knowledge
Which of the following statements correctly describe the benefits of using containers and container orchestration?
Recap: Docker & Kubernetes
You've taken a big step into cloud-native development!
- Containers package apps and dependencies into isolated, portable units.
- Docker is the popular tool to build and run these containers.
- Kubernetes orchestrates containers at scale, automating deployment, scaling, and management.
Together, they form the backbone for building resilient, scalable modern applications.
الأسئلة الشائعة
هل درس «الحاويات باستخدام Docker وK8s» مجاني؟
نعم — نص درس «الحاويات باستخدام Docker وK8s» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة System Design Basics for Backend Developers، انتقل إلى CoddyKit PRO. تتضمن دورة System Design Basics for Backend Developers 4 دروس في المجموع.
ماذا ستتعلم في «الحاويات باستخدام Docker وK8s»؟
أتقن استخدام Docker لتحويل التطبيقات إلى حاويات، وKubernetes لتنسيق أعباء العمل الحاوية على نطاق واسع. تتمرن على System Design Basics for Backend Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ System Design Basics for Backend Developers؟
لا تُشترط خبرة سابقة. System Design Basics for Backend Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «الحاويات باستخدام Docker وK8s»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس System Design Basics for Backend Developers هذا؟
نعم. كل درس في System Design Basics for Backend Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- البنى عديمة الخوادم
- الحاويات باستخدام Docker وK8s
- قابلية الملاحظة والتتبع الموزع
- البنية التحتية كتعليمة برمجية