0Pricing
Linux Networking & TCP/IP for Developers · درس

أوضاع شبكات Docker

استكشف برامج تشغيل الشبكات المختلفة في Docker (bridge وhost وoverlay)، وافهم آثارها على اتصال الحاويات.

أوضاع شبكات Docker درس مجاني في Linux Networking & TCP/IP for Developers على CoddyKit. هذا هو الدرس 1 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Linux Networking & TCP/IP for Developers، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.

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

Containers Need to Talk!

Docker containers are isolated by default, but they often need to communicate with each other or the outside world. Docker provides various network drivers to manage this.

These drivers define how containers connect to each other and to the host machine's network, ensuring proper communication and isolation.

The Standard: Bridge Network

When you don't specify a network, Docker automatically uses the default bridge network. Think of it as a virtual switch that Docker creates on your host machine.

Each container connected to this bridge gets its own IP address and can communicate with other containers on the same bridge using their IP addresses.

Default Bridge in Action

Let's inspect the default bridge network and see a container connected to it. This demonstrates how Docker assigns IP addresses within this virtual network.

Run these commands to observe the default bridge and a container's IP.

docker network ls
docker run -d --name mynginx nginx
docker inspect --format='{{.NetworkSettings.IPAddress}}' mynginx
docker stop mynginx
docker rm mynginx

Sharing Host's Network

The host network mode removes network isolation between the container and the host. The container directly uses the host's network stack.

This means the container's ports are directly exposed on the host's IP address without any port mapping. It offers high performance but significantly reduces isolation.

Host Mode Demo

When a container runs in host mode, it effectively becomes another process on the host's network. Its network interfaces and IP addresses will mirror those of the host machine.

Run this command to see a container's network details in host mode and compare it to your host's network configuration.

docker run --rm --network host alpine ip a
# Compare with your host's `ip a` output!

Spanning Multiple Hosts: Overlay

Overlay networks are designed for multi-host container communication, typically used in Docker Swarm or Kubernetes clusters.

They allow containers on different physical or virtual machines to communicate seamlessly as if they were on the same local network. This is vital for distributed applications.

Customizing Your Bridges

While the default bridge is useful, user-defined bridge networks are best practice. They offer several advantages over the default bridge:

  • Better Isolation: Keeps your application's network separate.
  • Automatic DNS: Containers can find each other by name, not just IP!
  • Portability: Easier to move applications between hosts.

Creating a Custom Bridge

Let's create our own custom bridge network and connect containers to it. Observe how containers on the same user-defined bridge can resolve each other by their container names.

This makes inter-container communication much simpler and more robust.

docker network create myapp_network
docker run -d --name myapp_server --network myapp_network alpine/git sh -c "while true; do echo 'Hello from server!' | nc -l -p 8080; done"
docker run --rm --network myapp_network alpine/git sh -c "apk add --no-cache netcat-openbsd && sleep 2 && nc myapp_server 8080"
docker stop myapp_server
docker rm myapp_server
docker network rm myapp_network

Containers Talking by Name

In the previous example, the client container successfully connected to myapp_server using its container name. This is a key advantage of user-defined bridge networks.

Docker's built-in DNS service automatically resolves container names to their IP addresses within the custom network, simplifying service discovery.

Test Your Knowledge!

Which of the following statements about Docker network modes are TRUE?

Docker Networks: A Quick Review

We've explored key Docker network modes that enable container communication:

  • Bridge: The default, for single-host container communication.
  • Host: Container shares the host's network stack for high performance but less isolation.
  • Overlay: For multi-host communication in clustered environments like Docker Swarm.
  • User-Defined Bridge: Best practice for custom app networks, offering isolation and automatic DNS resolution by name.

Understanding these modes is vital for designing robust and scalable containerized applications.

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

هل درس «أوضاع شبكات Docker» مجاني؟

نعم — نص درس «أوضاع شبكات Docker» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Linux Networking & TCP/IP for Developers، انتقل إلى CoddyKit PRO. تتضمن دورة Linux Networking & TCP/IP for Developers 4 دروس في المجموع.

ماذا ستتعلم في «أوضاع شبكات Docker»؟

استكشف برامج تشغيل الشبكات المختلفة في Docker (bridge وhost وoverlay)، وافهم آثارها على اتصال الحاويات. تتمرن على Linux Networking & TCP/IP for Developers مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Linux Networking & TCP/IP for Developers؟

لا تُشترط خبرة سابقة. Linux Networking & TCP/IP for Developers على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 1 من أصل 4.

كم من الوقت يستغرق درس «أوضاع شبكات Docker»؟

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

هل يمكنني كتابة وتشغيل أكواد في درس Linux Networking & TCP/IP for Developers هذا؟

نعم. كل درس في Linux Networking & TCP/IP for Developers يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. أوضاع شبكات Docker
  2. أساسيات شبكات Kubernetes
  3. سياسات الشبكة في الحاويات
  4. اكتشاف الخدمات وDNS في Kubernetes
← العودة إلى Linux Networking & TCP/IP for Developers