Skip to content

Commit

Permalink
fix: DOCKER_HOST handling of unix sockets (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
serverwentdown authored May 13, 2022
1 parent c1d8e30 commit f644103
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 19 additions & 4 deletions docs/usage/advanced/podman.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ 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
```

Alternatively, set DOCKER_HOST when running k3d:
Alternatively, set `DOCKER_HOST` when running k3d:

```bash
export DOCKER_HOST=unix:///run/podman/podman.sock
sudo --preserve-env=DOCKER_HOST k3d cluster create
export DOCKER_SOCK=/run/podman/podman.sock
sudo --preserve-env=DOCKER_HOST --preserve-env=DOCKER_SOCK k3d cluster create
```

### Using rootless Podman
Expand All @@ -38,11 +39,22 @@ systemctl --user enable --now podman.socket
# or podman system service --time=0
```

Set DOCKER_HOST when running k3d:
Set `DOCKER_HOST` when running k3d:

```bash
XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/run/user/$(id -u)}
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/podman/podman.sock
export DOCKER_SOCK=$XDG_RUNTIME_DIR/podman/podman.sock
k3d cluster create
```

### Using remote Podman

[Start Podman on the remote host](https://github.com/containers/podman/blob/main/docs/tutorials/remote_client.md), and then set `DOCKER_HOST` when running k3d:

```
export DOCKER_HOST=ssh://username@hostname
export DOCKER_SOCK=/run/user/1000/podman/podman.sock
k3d cluster create
```

Expand All @@ -62,3 +74,6 @@ k3d cluster create --registry-use mycluster-registry mycluster

!!! note "Incompatibility with `--registry-create`"
Because `--registry-create` assumes the default network to be "bridge", avoid `--registry-create` when using Podman. Instead, always create a registry before creating a cluster.

!!! note "Missing cpuset cgroup controller"
If you experince an error regarding missing cpuset cgroup controller, ensure the user unit `xdg-document-portal.service` is disabled by running `systemctl --user stop xdg-document-portal.service`. See [this issue](https://github.com/systemd/systemd/issues/18293#issuecomment-831397578)
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 f644103

Please sign in to comment.