Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add work-around for Docker Desktop breaking /etc/hosts #3104

Merged
merged 1 commit into from
Jul 18, 2023
Merged
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
5 changes: 5 additions & 0 deletions pkg/chezmoi/chezmoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ func etcHostsFQDNHostname(fileSystem vfs.FS) (string, error) {
if domainname == "localdomain" {
continue
}
// Docker Desktop breaks /etc/hosts. Filter out all docker.internal
// domain names. See https://github.com/twpayne/chezmoi/issues/3095.
if domainname == "docker.internal" {
continue
}
if runtime.GOOS == "darwin" && domainname == "local" {
continue
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/chezmoi/chezmoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ func TestEtcHostsFQDNHostname(t *testing.T) {
f: etcHostsFQDNHostname,
expected: "host.example.com",
},
{
name: "etc_hosts_kubernetes_docker_internal",
root: map[string]any{
"/etc/hosts": chezmoitest.JoinLines(
`##`,
`# Host Database`,
`#`,
`# localhost is used to configure the loopback interface`,
`# when the system is booting. Do not change this entry.`,
`##`,
`127.0.0.1 localhost`,
`255.255.255.255 broadcasthost`,
`::1 localhost`,
`# Added by Docker Desktop`,
`# To allow the same kube context to work on the host and the container:`,
`127.0.0.1 kubernetes.docker.internal`,
`# End of section`,
`127.0.1.1`,
`127.0.1.1 host.example.com`,
),
},
f: etcHostsFQDNHostname,
expected: "host.example.com",
},
{
name: "etc_hostname",
root: map[string]any{
Expand Down
Loading