Skip to content

Commit

Permalink
fix: DOCKER_HOST handling of unix sockets
Browse files Browse the repository at this point in the history
In a580edb, GetHost() introduced code
to handle the DfD use case. However, it also caused "unix:///" DOCKER_HOST
values to be parsed incorrectly. This resulted in kubeconfigs containing
"unix" as the hostname.

This patch ensures all "unix:///" DOCKER_HOST values are parsed as an
empty host (and thus set as 0.0.0.0 in kubeconfig)
  • Loading branch information
serverwentdown committed Apr 9, 2022
1 parent 74c574c commit d915ae6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/usage/advanced/podman.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ sudo systemctl enable --now podman.socket
To point k3d at the right Docker socket, create a symbolic link:

```bash
ln -s /run/podman/podman.sock /var/run/docker.sock
sudo ln -s /run/podman/podman.sock /var/run/docker.sock
# or install your system podman-docker if available
sudo k3d cluster create
```
Expand Down
10 changes: 4 additions & 6 deletions pkg/runtimes/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ THE SOFTWARE.
package docker

import (
"fmt"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -72,11 +73,12 @@ func (d Docker) GetHost() string {
return ""
}
l.Log().Debugln("[Docker] Local DfD: using 'host.docker.internal'")
dockerHost = "host.docker.internal"
if _, err := net.LookupHost(dockerHost); err != nil {
dfdHost := "host.docker.internal"
if _, err := net.LookupHost(dfdHost); err != nil {
l.Log().Debugf("[Docker] wanted to use 'host.docker.internal' as docker host, but it's not resolvable locally: %v", err)
return ""
}
dockerHost = fmt.Sprintf("tcp://%s", dfdHost)
}
}
url, err := url.Parse(dockerHost)
Expand All @@ -85,10 +87,6 @@ func (d Docker) GetHost() string {
return ""
}
dockerHost = url.Host
// apparently, host.docker.internal is not parsed as host but
if dockerHost == "" && url.String() != "" {
dockerHost = url.String()
}
l.Log().Debugf("[Docker] DockerHost: '%s' (%+v)", dockerHost, url)

return dockerHost
Expand Down

0 comments on commit d915ae6

Please sign in to comment.