高级java每日一道面试题-2027年01月31日-实战篇[Docker]-如何实现容器网络的隔离和安全? - 如果多个团队共用 Docker 主机,如何保证网络隔离
容器网络隔离与安全是构建“零信任”微服务架构的基础。在 Java 企业应用中,不同业务的微服务、数据库、中间件需运行在严格受限的网络边界内,以防止横向移动攻击,保障数据仅经过加密信道传输。以下从隔离、准入与加密三个层面阐述。
一、网络隔离的层次模型
Docker 提供了从宽松到严格的多种网络隔离模式,可组合实现纵深防御。 拼多多帮助力入口
#mermaid-svg-0BsJg52BgGh5TtLM{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-0BsJg52BgGh5TtLM .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-0BsJg52BgGh5TtLM .error-icon{fill:#552222;}#mermaid-svg-0BsJg52BgGh5TtLM .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-0BsJg52BgGh5TtLM .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-0BsJg52BgGh5TtLM .marker{fill:#333333;stroke:#333333;}#mermaid-svg-0BsJg52BgGh5TtLM .marker.cross{stroke:#333333;}#mermaid-svg-0BsJg52BgGh5TtLM svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-0BsJg52BgGh5TtLM p{margin:0;}#mermaid-svg-0BsJg52BgGh5TtLM .edge{stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .section--1 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section--1 path,#mermaid-svg-0BsJg52BgGh5TtLM .section--1 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section--1 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section--1 text{fill:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth--1{stroke-width:17;}#mermaid-svg-0BsJg52BgGh5TtLM .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-0 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-0 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-0 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-0 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-0 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-0{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-0{stroke-width:14;}#mermaid-svg-0BsJg52BgGh5TtLM .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-1 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-1 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-1 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-1 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-1 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-1{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-1{stroke-width:11;}#mermaid-svg-0BsJg52BgGh5TtLM .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-2 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-2 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-2 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-2 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-2 text{fill:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-2{stroke-width:8;}#mermaid-svg-0BsJg52BgGh5TtLM .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-3 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-3 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-3 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-3 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-3 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-3{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-3{stroke-width:5;}#mermaid-svg-0BsJg52BgGh5TtLM .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-4 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-4 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-4 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-4 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-4 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-4{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-4{stroke-width:2;}#mermaid-svg-0BsJg52BgGh5TtLM .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-5 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-5 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-5 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-5 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-5 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-5{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-5{stroke-width:-1;}#mermaid-svg-0BsJg52BgGh5TtLM .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-6 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-6 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-6 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-6 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-6 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-6{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-6{stroke-width:-4;}#mermaid-svg-0BsJg52BgGh5TtLM .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-7 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-7 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-7 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-7 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-7 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-7{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-7{stroke-width:-7;}#mermaid-svg-0BsJg52BgGh5TtLM .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-8 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-8 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-8 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-8 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-8 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-8{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-8{stroke-width:-10;}#mermaid-svg-0BsJg52BgGh5TtLM .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-9 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-9 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-9 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-9 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-9 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-9{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-9{stroke-width:-13;}#mermaid-svg-0BsJg52BgGh5TtLM .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-10 rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-10 path,#mermaid-svg-0BsJg52BgGh5TtLM .section-10 circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-10 polygon,#mermaid-svg-0BsJg52BgGh5TtLM .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-10 text{fill:black;}#mermaid-svg-0BsJg52BgGh5TtLM .node-icon-10{font-size:40px;color:black;}#mermaid-svg-0BsJg52BgGh5TtLM .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .edge-depth-10{stroke-width:-16;}#mermaid-svg-0BsJg52BgGh5TtLM .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled,#mermaid-svg-0BsJg52BgGh5TtLM .disabled circle,#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:lightgray;}#mermaid-svg-0BsJg52BgGh5TtLM .disabled text{fill:#efefef;}#mermaid-svg-0BsJg52BgGh5TtLM .section-root rect,#mermaid-svg-0BsJg52BgGh5TtLM .section-root path,#mermaid-svg-0BsJg52BgGh5TtLM .section-root circle,#mermaid-svg-0BsJg52BgGh5TtLM .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-0BsJg52BgGh5TtLM .section-root text{fill:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .section-root span{color:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .section-2 span{color:#ffffff;}#mermaid-svg-0BsJg52BgGh5TtLM .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-0BsJg52BgGh5TtLM .edge{fill:none;}#mermaid-svg-0BsJg52BgGh5TtLM .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-0BsJg52BgGh5TtLM :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}容器网络隔离与安全网络模式隔离自定义多主机Macvlan / IpvlanHost / None网络策略隔离子网划分iptables容器标签与网络段绑定应用层隔离mTLS 服务网格API 网关认证与授权
二、主要隔离手段及原理
隔离手段原理隔离强度适用场景Java 安全实践自定义 Bridge 网络每个 Docker 网络拥有独立网络命名空间、虚拟网桥和子网。不同网络间默认不通,除非容器加入多个网络。中等(IP 层可达性控制)单主机内按业务划分网络,如订单网络、支付网络。订单服务与支付服务各自在不同网络,仅通过共享网络暴露必要接口。内部网络 (--internal)创建网络时启用内部模式,容器可内部通信,但禁止访问外部网络(出站)。强(无出站 NAT)数据库、缓存等仅需被服务访问且不应连接外网的组件。MySQL 容器放入内部网络,只能由应用容器访问,无法向外发送数据。Overlay 网络加密在 Swarm 集群中启用 --opt encrypted,使用 IPsec 加密 VXLAN 隧道中的数据。高(传输加密)跨主机敏感流量,防止窃听。跨节点的微服务调用自动加密,无需应用改造。网络策略 (Calico/Cilium)基于标签的细粒度访问控制,定义哪些 Pod/容器可以访问哪些服务的哪些端口。极高(微隔离)Kubernetes 或集成 CNI 插件环境。只允许商品服务访问订单服务的特定端口,拒绝其他所有连接。防火墙与 iptables在宿主机或容器内部使用 iptables 自定义规则,限制来源 IP、端口、协议。高(宿主机层)混合部署环境,精确控制流量。限制某个 Java 管理接口只能从特定 IP 访问。三、多层网络隔离架构
一个典型的安全隔离方案将业务切分为多个安全域:
#mermaid-svg-wNhQEkqBqzUKIlMn{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-wNhQEkqBqzUKIlMn .error-icon{fill:#552222;}#mermaid-svg-wNhQEkqBqzUKIlMn .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-wNhQEkqBqzUKIlMn .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-wNhQEkqBqzUKIlMn .marker{fill:#333333;stroke:#333333;}#mermaid-svg-wNhQEkqBqzUKIlMn .marker.cross{stroke:#333333;}#mermaid-svg-wNhQEkqBqzUKIlMn svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-wNhQEkqBqzUKIlMn p{margin:0;}#mermaid-svg-wNhQEkqBqzUKIlMn .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster-label text{fill:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster-label span{color:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster-label span p{background-color:transparent;}#mermaid-svg-wNhQEkqBqzUKIlMn .label text,#mermaid-svg-wNhQEkqBqzUKIlMn span{fill:#333;color:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn .node rect,#mermaid-svg-wNhQEkqBqzUKIlMn .node circle,#mermaid-svg-wNhQEkqBqzUKIlMn .node ellipse,#mermaid-svg-wNhQEkqBqzUKIlMn .node polygon,#mermaid-svg-wNhQEkqBqzUKIlMn .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-wNhQEkqBqzUKIlMn .rough-node .label text,#mermaid-svg-wNhQEkqBqzUKIlMn .node .label text,#mermaid-svg-wNhQEkqBqzUKIlMn .image-shape .label,#mermaid-svg-wNhQEkqBqzUKIlMn .icon-shape .label{text-anchor:middle;}#mermaid-svg-wNhQEkqBqzUKIlMn .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-wNhQEkqBqzUKIlMn .rough-node .label,#mermaid-svg-wNhQEkqBqzUKIlMn .node .label,#mermaid-svg-wNhQEkqBqzUKIlMn .image-shape .label,#mermaid-svg-wNhQEkqBqzUKIlMn .icon-shape .label{text-align:center;}#mermaid-svg-wNhQEkqBqzUKIlMn .node.clickable{cursor:pointer;}#mermaid-svg-wNhQEkqBqzUKIlMn .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-wNhQEkqBqzUKIlMn .arrowheadPath{fill:#333333;}#mermaid-svg-wNhQEkqBqzUKIlMn .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-wNhQEkqBqzUKIlMn .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-wNhQEkqBqzUKIlMn .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-wNhQEkqBqzUKIlMn .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-wNhQEkqBqzUKIlMn .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-wNhQEkqBqzUKIlMn .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster text{fill:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn .cluster span{color:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-wNhQEkqBqzUKIlMn .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-wNhQEkqBqzUKIlMn rect.text{fill:none;stroke-width:0;}#mermaid-svg-wNhQEkqBqzUKIlMn .icon-shape,#mermaid-svg-wNhQEkqBqzUKIlMn .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-wNhQEkqBqzUKIlMn .icon-shape p,#mermaid-svg-wNhQEkqBqzUKIlMn .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-wNhQEkqBqzUKIlMn .icon-shape .label rect,#mermaid-svg-wNhQEkqBqzUKIlMn .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-wNhQEkqBqzUKIlMn .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-wNhQEkqBqzUKIlMn .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-wNhQEkqBqzUKIlMn :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}宿主机数据网络: data-net --internal应用网络: app-net前端网络: dmz-net允许出站默认拒绝出站无外网接口Nginx / Web 容器订单服务支付服务MySQLRedis互联网
前端网络 (dmz-net):接受外部流量,可访问应用网络。应用网络 (app-net):处理业务逻辑,可访问数据网络,但限制出站。数据网络 (data-net):设为 --internal,无法访问外部,仅被应用网络访问。
四、安全通信:加密与身份
仅隔离不够,流量内容可能被嗅探或篡改。需叠加加密和身份验证。
Overlay 网络加密:Swarm 模式下启用 --opt encrypted,对 Overlay 网络数据平面进行 IPSec 加密,节点间自动协商密钥。无需修改 Java 应用。mTLS 服务网格:如 Istio/Linkerd,为每个容器注入 Sidecar 代理,实现容器间自动 mTLS、细粒度授权和遥测。适合大型微服务安全体系。自签证书与内部 CA:在 Java 应用中配置 SSL/TLS,微服务间使用证书相互认证。Spring Boot 可配置 server.ssl.* 和 RestTemplate 的 SSL 上下文。
五、隔离与安全的实施流程
容器网络管理Docker Daemon安全管理员容器网络管理Docker Daemon安全管理员#mermaid-svg-LgapAjzRsI1dqkc5{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-LgapAjzRsI1dqkc5 .error-icon{fill:#552222;}#mermaid-svg-LgapAjzRsI1dqkc5 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-LgapAjzRsI1dqkc5 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-LgapAjzRsI1dqkc5 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-LgapAjzRsI1dqkc5 .marker.cross{stroke:#333333;}#mermaid-svg-LgapAjzRsI1dqkc5 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-LgapAjzRsI1dqkc5 p{margin:0;}#mermaid-svg-LgapAjzRsI1dqkc5 .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-LgapAjzRsI1dqkc5 text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-LgapAjzRsI1dqkc5 .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-LgapAjzRsI1dqkc5 .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-LgapAjzRsI1dqkc5 #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-LgapAjzRsI1dqkc5 .sequenceNumber{fill:white;}#mermaid-svg-LgapAjzRsI1dqkc5 #sequencenumber{fill:#333;}#mermaid-svg-LgapAjzRsI1dqkc5 #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-LgapAjzRsI1dqkc5 .messageText{fill:#333;stroke:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-LgapAjzRsI1dqkc5 .labelText,#mermaid-svg-LgapAjzRsI1dqkc5 .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .loopText,#mermaid-svg-LgapAjzRsI1dqkc5 .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-LgapAjzRsI1dqkc5 .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-LgapAjzRsI1dqkc5 .noteText,#mermaid-svg-LgapAjzRsI1dqkc5 .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-LgapAjzRsI1dqkc5 .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-LgapAjzRsI1dqkc5 .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-LgapAjzRsI1dqkc5 .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-LgapAjzRsI1dqkc5 .actorPopupMenu{position:absolute;}#mermaid-svg-LgapAjzRsI1dqkc5 .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-LgapAjzRsI1dqkc5 .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-LgapAjzRsI1dqkc5 .actor-man circle,#mermaid-svg-LgapAjzRsI1dqkc5 line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-LgapAjzRsI1dqkc5 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}应用容器现在有两个接口:app-net 用于对外,data-net 用于访问数据库创建隔离网络docker network create --internal data-net建立独立命名空间和网桥,禁止 NAT创建应用网络 app-net运行数据库容器docker run --network data-net mysql运行应用容器docker run --network app-net ...连接应用到数据库网络docker network connect data-net app-container配置 iptables 规则限制访问(例如只允许 app-net IP 访问数据库端口)启用 Overlay 加密 (如跨主机)自动管理 IPsec 隧道
六、与 Kubernetes 网络策略对比
面试常会延伸至 K8s。Docker 原生策略较弱,通常需 CNI 插件(Calico、Cilium)强化。Docker Swarm 也不支持原生 NetworkPolicy 资源,但可通过服务约束(network 的 driver_opts)或第三方集成实现微隔离。现代趋势是将安全策略左移,与编排深度结合。
七、Java 面试追问与回答
1. 如何防止容器之间的端口扫描?
使用 --internal 网络禁用外网,自定义 Bridge 网络隔离,结合宿主机 iptables 禁止非白名单 IP 访问。
2. Spring Boot 微服务如何配合容器网络安全?
将敏感服务(如付款)部署在独立 Overlay 网络,不暴露到前端。应用配置文件使用服务名而非 IP,配合 Docker DNS。启用 actuator health 端点时,用不同端口仅暴露给监控网络。
3. 如果多个团队共用 Docker 主机,如何保证网络隔离?
为每个团队创建独立的自定义 Bridge 网络,项目间网络不可见。使用角色权限控制(如 Docker EE 或第三方),限制团队只能管理自己的网络。
4. 容器网络隔离对性能有影响吗?
自定义 Bridge 和 Overlay 网络几乎无额外性能开销(Overlay 加密增加 CPU)。合理规划子网,避免过多 iptables 规则导致遍历延迟。
八、思维导图总结
#mermaid-svg-cgEzH0bp2kwfV4hm{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-cgEzH0bp2kwfV4hm .error-icon{fill:#552222;}#mermaid-svg-cgEzH0bp2kwfV4hm .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-cgEzH0bp2kwfV4hm .marker{fill:#333333;stroke:#333333;}#mermaid-svg-cgEzH0bp2kwfV4hm .marker.cross{stroke:#333333;}#mermaid-svg-cgEzH0bp2kwfV4hm svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-cgEzH0bp2kwfV4hm p{margin:0;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge{stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 path{fill:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 text{fill:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon--1{font-size:40px;color:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge--1{stroke:hsl(240, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth--1{stroke-width:17;}#mermaid-svg-cgEzH0bp2kwfV4hm .section--1 line{stroke:hsl(60, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 path{fill:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-0{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-0{stroke:hsl(60, 100%, 73.5294117647%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-0{stroke-width:14;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-0 line{stroke:hsl(240, 100%, 83.5294117647%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 path{fill:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-1{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-1{stroke:hsl(80, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-1{stroke-width:11;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-1 line{stroke:hsl(260, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 path{fill:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 text{fill:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-2{font-size:40px;color:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-2{stroke:hsl(270, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-2{stroke-width:8;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 line{stroke:hsl(90, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 path{fill:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-3{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-3{stroke:hsl(300, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-3{stroke-width:5;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-3 line{stroke:hsl(120, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 path{fill:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-4{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-4{stroke:hsl(330, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-4{stroke-width:2;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-4 line{stroke:hsl(150, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 path{fill:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-5{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-5{stroke:hsl(0, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-5{stroke-width:-1;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-5 line{stroke:hsl(180, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 path{fill:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-6{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-6{stroke:hsl(30, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-6{stroke-width:-4;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-6 line{stroke:hsl(210, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 path{fill:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-7{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-7{stroke:hsl(90, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-7{stroke-width:-7;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-7 line{stroke:hsl(270, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 path{fill:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-8{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-8{stroke:hsl(150, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-8{stroke-width:-10;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-8 line{stroke:hsl(330, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 path{fill:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-9{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-9{stroke:hsl(180, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-9{stroke-width:-13;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-9 line{stroke:hsl(0, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 polygon,#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 path{fill:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 text{fill:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .node-icon-10{font-size:40px;color:black;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-edge-10{stroke:hsl(210, 100%, 76.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .edge-depth-10{stroke-width:-16;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-10 line{stroke:hsl(30, 100%, 86.2745098039%);stroke-width:3;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled circle,#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:lightgray;}#mermaid-svg-cgEzH0bp2kwfV4hm .disabled text{fill:#efefef;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-root rect,#mermaid-svg-cgEzH0bp2kwfV4hm .section-root path,#mermaid-svg-cgEzH0bp2kwfV4hm .section-root circle,#mermaid-svg-cgEzH0bp2kwfV4hm .section-root polygon{fill:hsl(240, 100%, 46.2745098039%);}#mermaid-svg-cgEzH0bp2kwfV4hm .section-root text{fill:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-root span{color:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .section-2 span{color:#ffffff;}#mermaid-svg-cgEzH0bp2kwfV4hm .icon-container{height:100%;display:flex;justify-content:center;align-items:center;}#mermaid-svg-cgEzH0bp2kwfV4hm .edge{fill:none;}#mermaid-svg-cgEzH0bp2kwfV4hm .mindmap-node-label{dy:1em;alignment-baseline:middle;text-anchor:middle;dominant-baseline:middle;text-align:center;}#mermaid-svg-cgEzH0bp2kwfV4hm :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}容器网络隔离与安全隔离技术自定义 Bridge 网络内部网络 --internalOverlay 网络加密Macvlan 物理隔离准入控制CNI防火墙规则容器级 iptables传输安全Overlay 加密应用层TLS 证书管理Java 实战服务名通信 + DNS敏感网络隔离数据源多网络接口应用合规审计日志网络流量监控漏洞扫描集成
总结:容器网络隔离不是单一的开关,而是 “模式隔离 + 策略限制 + 加密传输” 的组合。在 Java 微服务中,通过将不同安全级别的服务放入不同网络,并限制访问流向,再叠加 Overlay 加密或应用层 mTLS,可构建纵深防御体系,满足企业级安全与合规要求。,高级java每日一道面试题