Skip to content

Commit

Permalink
Merge pull request #1592 from Luap99/etchosts-docker-entry
Browse files Browse the repository at this point in the history
libnetwork/etchosts: add docker.internal dns entries
  • Loading branch information
openshift-merge-robot authored Aug 1, 2023
2 parents 25ef52f + 00706e1 commit cac4013
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion libnetwork/etchosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
HostContainersInternal = "host.containers.internal"
HostGateway = "host-gateway"
localhost = "localhost"
hostDockerInternal = "host.docker.internal"
)

type HostEntries []HostEntry
Expand Down Expand Up @@ -119,7 +120,7 @@ func newHost(params *Params) error {
l2 := HostEntry{IP: "::1", Names: lh}
containerIPs = append(containerIPs, l1, l2)
if params.HostContainersInternalIP != "" {
e := HostEntry{IP: params.HostContainersInternalIP, Names: []string{HostContainersInternal}}
e := HostEntry{IP: params.HostContainersInternalIP, Names: []string{HostContainersInternal, hostDockerInternal}}
containerIPs = append(containerIPs, e)
}
containerIPs = append(containerIPs, params.ContainerIPs...)
Expand Down
17 changes: 12 additions & 5 deletions libnetwork/etchosts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ const targetFileContent5 = `1.1.1.1 name1

const baseFileContent6 = `127.0.0.1 localhost
::1 localhost
1.1.1.1 host.containers.internal
1.1.1.1 host.containers.internal host.docker.internal
`

const targetFileContent6 = `127.0.0.1 localhost
::1 localhost
1.1.1.1 host.containers.internal
1.1.1.1 host.containers.internal host.docker.internal
`

const baseFileContent7 = `
Expand Down Expand Up @@ -216,21 +216,28 @@ func TestNew(t *testing.T) {
name: "with host.containers.internal ip",
baseFileContent: baseFileContent1Spaces,
hostContainersInternal: "10.0.0.1",
expectedTargetFileContent: targetFileContent1 + "10.0.0.1\thost.containers.internal\n",
expectedTargetFileContent: targetFileContent1 + "10.0.0.1\thost.containers.internal host.docker.internal\n",
},
{
name: "with host.containers.internal ip and host-gateway",
baseFileContent: baseFileContent1Spaces,
extraHosts: []string{"gatewayname:host-gateway"},
hostContainersInternal: "10.0.0.1",
expectedTargetFileContent: "10.0.0.1\tgatewayname\n" + targetFileContent1 + "10.0.0.1\thost.containers.internal\n",
expectedTargetFileContent: "10.0.0.1\tgatewayname\n" + targetFileContent1 + "10.0.0.1\thost.containers.internal host.docker.internal\n",
},
{
name: "host.containers.internal not added when already present in extra hosts",
baseFileContent: baseFileContent1Spaces,
extraHosts: []string{"host.containers.internal:1.1.1.1"},
hostContainersInternal: "10.0.0.1",
expectedTargetFileContent: "1.1.1.1\thost.containers.internal\n" + targetFileContent1,
expectedTargetFileContent: "1.1.1.1\thost.containers.internal\n" + targetFileContent1 + "10.0.0.1\thost.docker.internal\n",
},
{
name: "host.containers.internal and host.docker.internal not added when already present in extra hosts",
baseFileContent: baseFileContent1Spaces,
extraHosts: []string{"host.containers.internal:1.1.1.1", "host.docker.internal:1.1.1.1"},
hostContainersInternal: "10.0.0.1",
expectedTargetFileContent: "1.1.1.1\thost.containers.internal\n1.1.1.1\thost.docker.internal\n" + targetFileContent1,
},
{
name: "host.containers.internal not added when already present in base hosts",
Expand Down

0 comments on commit cac4013

Please sign in to comment.