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

fix: DOCKER_HOST handling of unix sockets #1045

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
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