docker-networking-knowledge

Docker 网络知识库,涵盖网络配置模式、DNS 解析、端口映射以及在 PHP 多服务场景中的服务间通信方案与实践。

仓库最近推送
GitHub Stars
109
Forks
26
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "docker-networking-knowledge":https://skillpi.com/zh/skills/deepskill-cb1b4d57e385c110444680168da908b5127c0d661e397787f9b20cd2822c434c。安装前核对上游来源和版本:https://github.com/dykyi-roman/awesome-claude-code。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

Docker 网络知识库,涵盖网络配置模式、DNS 解析、端口映射以及在 PHP 多服务场景中的服务间通信方案与实践。

0 下载

介绍来源: third_party · dykyi-roman · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: docker-networking-knowledge
description: Docker networking knowledge base. Provides network configuration patterns, DNS resolution, port mapping, and multi-service communication for PHP.

Docker Networking Knowledge Base

Network configuration patterns and communication strategies for PHP Docker stacks.

Network Types

Type Driver Use Case Isolation Performance
Bridge bridge Default single-host Container-level Good
Host host Maximum performance None (shares host) Best
Overlay overlay Multi-host (Swarm/K8s) Container-level Moderate
None none Complete isolation Full N/A
Macvlan macvlan Direct LAN access Network-level Good

PHP-FPM + Nginx Communication

TCP Socket (Default in Docker)

┌─────────────────────────────────────────────────────────────────────────────┐
│                     TCP SOCKET COMMUNICATION                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   Client ──▶ :80 ──▶ ┌─────────┐  TCP :9000  ┌──────────┐                 │
│                       │  Nginx  │ ──────────▶ │ PHP-FPM  │                 │
│                       └─────────┘              └──────────┘                 │
│                                                                              │
│   Nginx config: fastcgi_pass php:9000;                                      │
│   PHP-FPM config: listen = 0.0.0.0:9000                                    │
│                                                                              │
│   Pros: Works across containers, simple setup, scalable                     │
│   Cons: Slight overhead vs Unix socket                                      │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Unix Socket (Shared Volume)

┌─────────────────────────────────────────────────────────────────────────────┐
│                    UNIX SOCKET COMMUNICATION                                 │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│   Client ──▶ :80 ──▶ ┌─────────┐  /sock/fpm  ┌──────────┐                 │
│                       │  Nginx  │ ──────────▶ │ PHP-FPM  │                 │
│                       └────┬────┘              └────┬─────┘                 │
│                            │     shared volume      │                       │
│                            └────────┐  ┌────────────┘                       │
│                                     ▼  ▼                                    │
│                              ┌──────────────┐                               │
│                              │ /var/run/php/ │                               │
│                              │  php-fpm.sock │                               │
│                              └──────────────┘                               │
│                                                                              │
│   Nginx config: fastcgi_pass unix:/var/run/php/php-fpm.sock;               │
│   PHP-FPM config: listen = /var/run/php/php-fpm.sock                       │
│                                                                              │
│   Pros: ~5-10% faster, no TCP overhead                                      │
│   Cons: Requires shared volume, harder to scale                             │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

Compose configuration for Unix socket:

services:
  php:
    volumes:
      - php-socket:/var/run/php

  nginx:
    volumes:
      - php-socket:/var/run/php:ro

volumes:
  php-socket:

DNS Resolution in Compose

Docker Compose provides automatic DNS resolution using service names.

┌──────────────────────────────────────────────────────────┐
│              DNS RESOLUTION                                │
├──────────────────────────────────────────────────────────┤
│                                                           │
│   Service Name    ──▶  Container IP                       │
│   ────────────────────────────────────                    │
│   postgres        ──▶  172.20.0.2                         │
│   redis           ──▶  172.20.0.3                         │
│   rabbitmq        ──▶  172.20.0.4                         │
│   php             ──▶  172.20.0.5                         │
│   nginx           ──▶  172.20.0.6                         │
│                                                           │
│   Resolution scope: within same network only              │
│   Resolver: Docker embedded DNS (127.0.0.11)             │
│                                                           │
└──────────────────────────────────────────────────────────┘

PHP connection strings using service names:

// PostgreSQL
'postgresql://app:secret@postgres:5432/app'

// Redis
'redis://redis:6379'

// RabbitMQ
'amqp://guest:guest@rabbitmq:5672/%2f'

// Elasticsearch
'http://elasticsearch:9200'

DNS Aliases

services:
  postgres:
    networks:
      backend:
        aliases:
          - db
          - database
          - pg

Port Mapping Strategies

Pattern Syntax Visibility Use Case
Published ports: ["8080:80"] Host + containers Dev access, public services
Exposed expose: ["9000"] Containers only Internal services (FPM)
Host binding ports: ["127.0.0.1:5432:5432"] Localhost only Databases in dev
Random host ports: ["5432"] Random host port CI, parallel testing

Recommended Port Mapping

services:
  # Public-facing — bind to all interfaces
  nginx:
    ports:
      - "80:80"
      - "443:443"

  # Internal service — expose only (no host port)
  php:
    expose:
      - "9000"

  # Database — localhost only (dev security)
  postgres:
    ports:
      - "127.0.0.1:${POSTGRES_PORT:-5432}:5432"

  # Management UI — localhost only
  rabbitmq:
    ports:
      - "127.0.0.1:${RABBITMQ_MGMT_PORT:-15672}:15672"

Network Segmentation

networks:
  frontend:
    driver: bridge
    # Public-facing services (Nginx, Mailhog UI)

  backend:
    driver: bridge
    internal: true
    # Database, cache, queue — no external access

  monitoring:
    driver: bridge
    # Prometheus, Grafana, Jaeger

Segmentation Matrix

┌─────────────────────────────────────────────────────────────────┐
│   Service         │ frontend │ backend │ monitoring │ internet  │
│   ────────────────┼──────────┼─────────┼────────────┼────────── │
│   Nginx           │    ✓     │         │            │    ✓      │
│   PHP-FPM         │    ✓     │    ✓    │            │           │
│   Worker          │          │    ✓    │            │           │
│   Cron            │          │    ✓    │            │           │
│   PostgreSQL      │          │    ✓    │            │           │
│   Redis           │          │    ✓    │            │           │
│   RabbitMQ        │          │    ✓    │            │           │
│   Elasticsearch   │          │    ✓    │            │           │
│   Prometheus      │          │    ✓    │     ✓      │           │
│   Grafana         │          │         │     ✓      │    ✓      │
│   Jaeger          │          │    ✓    │     ✓      │           │
└─────────────────────────────────────────────────────────────────┘

The internal: true flag on the backend network prevents containers from reaching the internet, ensuring databases and caches are not exposed.

Inter-Container Communication

Same Network (Direct)

// Containers on the same network communicate directly via service name
$redis = new \Redis();
$redis->connect('redis', 6379);

Cross-Network (Shared Service)

services:
  php:
    networks:
      - frontend
      - backend    # PHP needs both to talk to Nginx AND database

  postgres:
    networks:
      - backend    # Only backend — no direct external access

Service Discovery Pattern

// Use environment variables for service endpoints
$dbHost = getenv('DATABASE_HOST') ?: 'postgres';
$redisHost = getenv('REDIS_HOST') ?: 'redis';
$amqpHost = getenv('AMQP_HOST') ?: 'rabbitmq';

host.docker.internal for Local Development

Access host machine services from within containers:

services:
  php:
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      # Connect to services running on host machine
      XDEBUG_CONFIG: "client_host=host.docker.internal"
Platform host.docker.internal Notes
Docker Desktop (Mac) Built-in Works automatically
Docker Desktop (Windows) Built-in Works automatically
Linux Requires extra_hosts Use host-gateway mapping

Troubleshooting

Issue Diagnosis Solution
Container cannot resolve service name Wrong network Ensure both services share a network
Connection refused between containers Port not exposed Add expose or check service is listening
Intermittent DNS failures (Alpine) musl resolver Add options ndots:0 to resolv.conf
Cannot reach host machine Missing extra_hosts Add host.docker.internal:host-gateway
External access to internal service Missing internal: true Mark backend network as internal
Port conflict on host Port already in use Use variable port mapping ${PORT:-5432}:5432

References

For service configuration examples, see docker-compose-knowledge. For base image networking considerations, see docker-base-images-knowledge.

当前收录版本

0.0.1

核对来源版本 ↗

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值95/100

亮点

  • Docker网络配置是开发运维中的核心痛点,内容覆盖全面,实用性强
  • 直接解决用户明确的核心任务痛点,如PHP多服务通信、DNS解析、端口映射等
触发精准90/100

亮点

  • 触发词精准完整,覆盖多种变体,边界清晰
  • description明确描述了Skill的核心功能和适用场景
结构规范90/100

亮点

  • Phase/步骤清晰,有出口条件,含端到端示例
  • frontmatter完整,单文件≤500行,结构规范
执行可靠90/100

亮点

  • 工具来源明确,参数正确,覆盖主要异常
  • 提供了详细的故障排除指南,确保执行可靠性
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • elasticsearch

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。