knative/func

Docker detection is broken on Mac OS X

Opened this issue · 4 comments

I have Docker Intel Mac installed (Docker Desktop 4.28.0 (139021) ) and the latest func (main@09537e382daa74fb58ffc11d7aa0929cd2729bd4) complains about DOCKER_HOST not being found

% func build
Building function image
Error: cannot create docker client: docker/podman API not available
Possible causes:
  The docker/podman daemon is not running.
  The DOCKER_HOST environment variable is not set.

It looks like Docker for Mac now supports different context

% docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                        KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock
desktop-linux *     moby                Docker Desktop                            unix:///Users/dprotasowski/.docker/run/docker.sock
orbstack            moby                OrbStack                                  unix:///Users/dprotasowski/.orbstack/run/docker.sock

I don't believe I added desktop-linux context - I'm assuming it came from upgrading Docker Desktop

I was under the impression you're attempting to use the "host" builder? If so, then the default builder is still either Pack or S2I, so you'll need to either explicitly choose the builder with --builder=host, or set the environment variable FUNC_BUILDER=host, or set a global default in ~.config/func/config.yaml of builder: host

Leaving this open, however, since this needs validation as a bug for those builders

vpsx commented

Hello, I hope it is appropriate to post this here. I seem to have the same issue on Linux:

~% docker version
Client: Docker Engine - Community
 Cloud integration: v1.0.35+desktop.13
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:09 2024
 OS/Arch:           linux/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.30.0 (149282)
 Engine:
  Version:          26.1.1
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.9
  Git commit:       ac2de55
  Built:            Tue Apr 30 11:48:28 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.31
  GitCommit:        e377cd56a71523140ca6ae87e30244719194a521
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
~% docker context ls
NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                 KUBERNETES ENDPOINT   ORCHESTRATOR
default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                           
desktop-linux *     moby                Docker Desktop                            unix:///home/vpsx/.docker/desktop/docker.sock    

Same error as above:

% kn func build
A registry for function images is required. For example, 'docker.io/tigerteam'.
? Registry for function images: docker.io/tigerteam
Note: building a function the first time will take longer than subsequent builds
Building function image
Error: cannot create docker client: docker/podman API not available
Possible causes:
  The docker/podman daemon is not running.
  The DOCKER_HOST environment variable is not set.
Error: exit status 1

Tried choosing --builder=host per above:

% kn func build --builder=host
A registry for function images is required. For example, 'docker.io/tigerteam'.
? Registry for function images: docker.io/tigerteam
Note: building a function the first time will take longer than subsequent builds
Error: "host" is not a known builder. Available builders are "pack" and "s2i"
Error: exit status 1
% kn func version
v0.41.0

Tried setting DOCKER_HOST; not sure if relevant, but it seems strange that it says dial unix /var/run/docker.sock after pointing DOCKER_HOST to the Docker Desktop daemon?

% export DOCKER_HOST=unix:///home/vpsx/.docker/desktop/docker.sock

% kn func build                                                                   
A registry for function images is required. For example, 'docker.io/tigerteam'.                
? Registry for function images: docker.io/tigerteam                                                                                                                                           Note: building a function the first time will take longer than subsequent builds                                                                                                              
Building function image                                                                                                                                                                       
Still building                                                                                                                                                                                
Still building
Yes, still building
Don't give up on me                                                                            
(.....)
c501d664298a: Pulling fs layer
139eebe90b6d: Pulling fs layer
ERROR: failed to initialize docker client: failed to connect to docker socket: dial unix /var/run/docker.sock: connect: connection refused
                                                                                               
Error: failed to build the function: executing lifecycle: failed with status code: 1
Error: exit status 1  

Many thanks in advance for any help.

I had the same issue. I am trying Rancher desktop. Someone on another issue for another project found the solution:

docker context list --format json 
export DOCKER_HOST=unix:///Users/stevef/.rd/docker.sock 
func build

The value to set in DOCKER_HOST is found from the 1st command above