Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ import (
"github.com/sirupsen/logrus"
)

type hostInfoStruct struct {
ipV4 net.IP
ipV6 net.IP
}

// HostInfo will be used to resolve host.docker.internal hostname to an address
var HostInfo *hostInfoStruct

// A Network represents a logical connectivity zone that containers may
// join using the Link method. A Network is managed by a specific driver.
type Network interface {
Expand Down Expand Up @@ -802,6 +810,15 @@ func NetworkOptionScope(scope string) NetworkOption {

// NetworkOptionIpam function returns an option setter for the ipam configuration for this network
func NetworkOptionIpam(ipamDriver string, addrSpace string, ipV4 []*IpamConf, ipV6 []*IpamConf, opts map[string]string) NetworkOption {
if ipamDriver == "default" && HostInfo == nil {
HostInfo = &hostInfoStruct{}
if len(ipV4) > 0 {
HostInfo.ipV4 = net.ParseIP(ipV4[0].Gateway)
}
if len(ipV6) > 0 {
HostInfo.ipV6 = net.ParseIP(ipV6[0].Gateway)
}
}
return func(n *network) {
if ipamDriver != "" {
n.ipamType = ipamDriver
Expand Down
19 changes: 18 additions & 1 deletion sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ type containerConfig struct {
}

const (
resolverIPSandbox = "127.0.0.11"
resolverIPSandbox = "127.0.0.11"
dnsOptResolveDockerInternal = "resolve-docker-internal"
hostDockerInternal = "host.docker.internal"
gatewayDockerInternal = "gateway.docker.internal"
)

func (sb *sandbox) ID() string {
Expand Down Expand Up @@ -401,6 +404,15 @@ func (sb *sandbox) getEndpoint(id string) *endpoint {
return nil
}

func (sb *sandbox) shouldResolveInternal() bool {
for _, opt := range sb.config.dnsOptionsList {
if opt == dnsOptResolveDockerInternal {
return true
}
}
return false
}

func (sb *sandbox) updateGateway(ep *endpoint) error {
sb.Lock()
osSbox := sb.osSbox
Expand Down Expand Up @@ -703,6 +715,11 @@ func (sb *sandbox) EnableService() (err error) {
return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
}
ep.enableService()
if ep.needResolver() && sb.shouldResolveInternal() {
ep.network.addSvcRecords(ep.ID(), hostDockerInternal, ep.svcID, HostInfo.ipV4, HostInfo.ipV6, true, "updateGateway")
ep.network.addSvcRecords(ep.ID(), gatewayDockerInternal, ep.svcID, HostInfo.ipV4, HostInfo.ipV6, true, "updateGateway")
}

}
}
logrus.Debugf("EnableService %s DONE", sb.containerID)
Expand Down