Skip to content

Network

一句话解释

容器 networking 定义如何容器 communicate 使用每个 other, host, and 外部 networks.

用大白话说

Container networking is about how containers talk to each other and to the outside world. Since containers are isolated, they need networking rules to communicate.

In Docker, the default bridge network lets containers on the same host communicate. You can also create custom networks for better isolation and DNS resolution (containers can reach each other by name).

In Kubernetes, networking is more sophisticated. Every Pod gets its own IP address, and Pods can communicate with any other Pod in the cluster without NAT. Services provide stable addresses, NetworkPolicies control traffic flow, and Ingress manages external access.

示例

bash
# Docker: create a custom network
docker network create mynet

# Run containers on the same network
docker run --network mynet --name api myapi
docker run --network mynet --name web myweb
# 'web' can now reach 'api' by hostname: http://api:3000

容器 on 相同自定义 network 能 reach 每个 other 通过容器 name as hostname.

工作原理

  1. Docker creates a virtual bridge or overlay network.
  2. Each container gets a virtual ethernet interface and IP.
  3. Containers on the same network can communicate by IP or DNS name.
  4. Kubernetes assigns each Pod an IP and handles routing across nodes.

常见混淆

  • 容易混淆的对象: Service

    关键区别: Networking 是 underlying communication mechanism; Service 是 Kubernetes 抽象那个 provides stable 地址 on 顶部的 network.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表