Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
full-statck-skills avatar

Docker Networking

  • 10 installs
  • 2 repo stars
  • Updated July 29, 2026
  • full-statck-skills/docker-skills

Configure Docker networking and inter-container communication across bridge, host, and overlay modes, with port mapping and network troubleshooting.

About

Guides Docker networking configuration and inter-container communication across network modes and port mapping. A developer uses it to connect containers or debug networking issues.

  • Network modes: bridge, host, overlay, none, macvlan, ipvlan with DNS resolution
  • Port publishing, service discovery, and network troubleshooting with inspect/ping/nslookup

Docker Networking by the numbers

  • 10 all-time installs (skills.sh)
  • Ranked #1,007 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
  • Data as of Jul 30, 2026 (Skillselion catalog sync)
npx skills add https://github.com/full-statck-skills/docker-skills --skill docker-networking

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs10
repo stars2
Last updatedJuly 29, 2026
Repositoryfull-statck-skills/docker-skills

What it does

Configure Docker networking and inter-container communication across bridge, host, and overlay modes, with port mapping and network troubleshooting.

Files

SKILL.mdMarkdownGitHub ↗

Docker Networking — 网络配置与容器通信

Comprehensive guidance for Docker networking modes, configuration, and troubleshooting.

When to Use

ALWAYS use this skill when the user mentions:

  • "docker network", "容器网络"
  • "bridge network", "host network", "overlay network"
  • "端口映射", "publish port"
  • "容器之间怎么通信", "跨容器通信"
  • "网络不通", "network troubleshooting"

Network Mode Comparison

ModeIsolationUse CaseCross-Host?
bridge (default)Container-levelSingle-host containers
hostNone (share host)Max performance, no isolation
overlayContainer-levelSwarm multi-host
noneFullNo networking needed
macvlan/ipvlanMAC/IP-levelLegacy apps needing physical IP

Custom Bridge Network (Recommended)

# Create a custom network
docker network create --driver bridge mynet

# Run containers on it
docker run -d --name app1 --network mynet nginx:alpine
docker run -d --name app2 --network mynet nginx:alpine

# DNS resolution works automatically
docker exec app1 ping app2    # ✅ responds
docker exec app1 nslookup app2  # ✅ resolves

# Benefits over default bridge:
# - Automatic DNS resolution
# - Container isolation from default bridge
# - Can connect/disconnect at runtime

Port Publishing

# Basic port mapping
docker run -p 8080:80 nginx     # host:8080 → container:80
docker run -p 8080              # random host port → container:8080
docker run -P nginx             # publish all EXPOSE'd ports to random host ports

# Multiple ports
docker run -p 8080:80 -p 8443:443 nginx

# Bind to specific interface
docker run -p 127.0.0.1:8080:80 nginx  # only localhost

Service Discovery

Custom bridge network provides automatic DNS:

┌──────────────────────────────────┐
│  my-network (bridge)             │
│                                  │
│  ┌──────┐  ┌──────┐  ┌──────┐   │
│  │ app1 │  │ app2 │  │  db  │   │
│  └──┬───┘  └──┬───┘  └──┬───┘   │
│     │         │         │        │
│     └─── DNS: app2 → 172.18.0.3 │
│          DNS: db → 172.18.0.4   │
└──────────────────────────────────┘

app1 can connect to db:5432 directly — no IP needed!

Overlay Network (Swarm)

# Create overlay for multi-host
docker network create --driver overlay --attachable my-overlay

# In compose:
networks:
  backend:
    driver: overlay

Network Troubleshooting

# Inspect network details
docker network inspect mynet

# Test connectivity from container
docker exec app1 ping -c 3 app2
docker exec app1 nslookup db
docker exec app1 curl http://app2:8080/health

# Check iptables (host)
sudo iptables -t nat -L DOCKER -n

Workflow — 推荐配置流程

Step 1: 确定需求: 容器间通信?端口暴露?跨主机?选择网络模式 Step 2: 创建网络: docker network create --driver bridge mynet Step 3: 启动容器: docker run -d --network mynet --name db mysql + docker run -d --network mynet --name api myapp Step 4: 验证连通性: docker exec api ping db(服务名 DNS 解析) Step 5: 排查问题: docker network inspect mynetdocker exec api nslookup db

Gotchas — Common Pitfalls

  • Default bridge no DNS: Containers on the default bridge CANNOT resolve each other by name. → Recovery: docker network create mynet && docker run --network mynet ...; always use custom bridge networks.
  • Port already in use: -p 8080:80 fails if host port 8080 is taken. → Recovery: lsof -i :8080 to find the process; use -p 8081:80 or -p 80 for random host port.
  • Mac host networking limitation: --network host on Docker Desktop (Mac) joins the VM's network, not the Mac's. → Recovery: Publish ports with -p instead of --network host.
  • Overlay without Swarm: Overlay networks only work with Swarm mode. → Recovery: docker swarm init first, or add --attachable flag for standalone containers.
  • EXPOSE does NOT publish: EXPOSE in Dockerfile is documentation only. → Recovery: Always use -p or Compose ports: to actually make ports accessible.

Boundary — 能力边界(适用与不适用场景)

分类场景说明
✅ 能做单机容器网络配置bridge/host/none 模式选择
✅ 能做容器间 DNS 通信自定义 bridge 网络 + 服务名解析
✅ 能做端口发布-p host:container 端口映射
⚠️ 需条件跨主机通信需要 overlay 网络 + Swarm 模式
⚠️ 需条件macOS --network host行为不同于 Linux,建议用 -p 替代
❌ 超范围K8s 网络策略(NetworkPolicy)使用 docker-production + K8s 文档
❌ 超范围外部负载均衡(Nginx/HAProxy)基础设施层级
❌ 超范围iptables/nftables 精细配置Linux 网络管理

When NOT to Use This Skill

❌ Skip✅ Use Instead
Docker basicsdocker-basics
Running containersdocker-run
Compose networkingdocker-compose (compose handles network creation automatically)
Kubernetes networkingK8s documentation

Security & Stability

  • Use --internal flag for networks that should not have internet access.
  • Encrypt overlay network traffic: --opt encrypted=true.
  • Avoid --network host in production — no network isolation.
  • No executable scripts bundled. Guidance only.

📚 官方文档参考

文档地址
Docker 网络概述https://docs.docker.com/network/
docker network 命令https://docs.docker.com/reference/cli/docker/network/
网络驱动https://docs.docker.com/network/drivers/
Bridge 网络https://docs.docker.com/network/bridge/
Overlay 网络https://docs.docker.com/network/overlay/
端口发布https://docs.docker.com/network/#published-ports

🧭 Docker Skills Journey

📍 You are here: `docker-networking` — 网络配置

← Previous: docker-run | → Next: docker-compose

FAQ

Q1: 如何快速上手此技能? A: 参考上方的快速开始章节,按步骤操作即可。

Q2: 遇到版本不兼容问题怎么办? A: 检查依赖版本,使用 lock 文件锁定,参考常见陷阱章节。

Q3: 如何在生产环境使用? A: 参考最佳实践章节,确保配置正确,做好监控和日志。

Q4: 性能如何优化? A: 参考性能优化相关文档,使用缓存、索引等手段。

Q5: 如何贡献或反馈问题? A: 在 GitHub 仓库提交 Issue 或 Pull Request。

Q6: 是否支持中文? A: 支持中文文档和中文注释,详见国内适配章节。

Related skills

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.