Skip to content

Commit 638ef31

Browse files
author
Santhosh Manohar
committed
Allow reachability across services on different networks in the same host
This also allows pubslied services to be accessible from containers on bridge networks on the same host Signed-off-by: Santhosh Manohar <santhosh@docker.com>
1 parent 82fb373 commit 638ef31

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

service_linux.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,31 @@ func programIngress(gwIP net.IP, ingressPorts []*PortConfig, isDelete bool) erro
544544
}
545545
}
546546

547+
// Filter table rules to allow a published service to be accessible in the local node from..
548+
// 1) service tasks attached to other networks
549+
// 2) unmanaged containers on bridge networks
550+
rule := strings.Fields(fmt.Sprintf("%s FORWARD -m state -p %s --sport %d --state ESTABLISHED,RELATED -j ACCEPT",
551+
addDelOpt, strings.ToLower(PortConfig_Protocol_name[int32(iPort.Protocol)]), iPort.PublishedPort))
552+
if err := iptables.RawCombinedOutput(rule...); err != nil {
553+
errStr := fmt.Sprintf("setting up rule failed, %v: %v", rule, err)
554+
if !isDelete {
555+
return fmt.Errorf("%s", errStr)
556+
}
557+
558+
logrus.Infof("%s", errStr)
559+
}
560+
561+
rule = strings.Fields(fmt.Sprintf("%s FORWARD -p %s --dport %d -j ACCEPT",
562+
addDelOpt, strings.ToLower(PortConfig_Protocol_name[int32(iPort.Protocol)]), iPort.PublishedPort))
563+
if err := iptables.RawCombinedOutput(rule...); err != nil {
564+
errStr := fmt.Sprintf("setting up rule failed, %v: %v", rule, err)
565+
if !isDelete {
566+
return fmt.Errorf("%s", errStr)
567+
}
568+
569+
logrus.Infof("%s", errStr)
570+
}
571+
547572
if err := plumbProxy(iPort, isDelete); err != nil {
548573
logrus.Warnf("failed to create proxy for port %d: %v", iPort.PublishedPort, err)
549574
}

0 commit comments

Comments
 (0)