skip to Main Content

Trying to run pack to build a Cloud Native Buildpack on Mac, it fails, complaining about not finding the expected Docker socket, where it usually is:

pack build my-app --builder paketobuildpacks/builder:base
ERROR: failed to build: failed to fetch builder image 'index.docker.io/paketobuildpacks/builder:base': 
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. 
Is the docker daemon running?

But all docker CLI commands such as docker ps work just fine. I am running Docker Desktop for Mac.

2

Answers


  1. Chosen as BEST ANSWER

    Explanation

    The problem turns out to be that Docker Desktop uses a different socket. It works because the docker CLI is set automatically to use the correct "context"). See:

    I too am running into this problem (with Docker Desktop for Mac), where pack build ... fails to connect b/c I have no /var/run/docker.sock - but the docker CLI itself works just fine. Thhe docker context explains why it is the case:

    $ docker context list
    NAME                TYPE                DESCRIPTION                               DOCKER ENDPOINT                                 KUBERNETES ENDPOINT                                 ORCHESTRATOR
    default             moby                Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                     https://kubernetes.docker.internal:6443 (default)   swarm
    desktop-linux *     moby                                                          unix:///Users/me/.docker/run/docker.sock
    
    $ docker context show
    desktop-linux
    

    so the default context uses the standard socket but is not active and the socket does not exist. Instead, the active context is desktop-linux, which uses a socket in the user's home dir (which does exist).

    There is an open (3/2023) pack issue to use docker context to get the correct host automatically.

    Solution

    The solution then is to point pack to the correct socket:

    env DOCKER_HOST=unix:///Users/me/.docker/run/docker.sock pack build my-app 
      --builder paketobuildpacks/builder:base
    

  2. To permanently fix the issue

    echo export DOCKER_HOST=unix:///Users/kiplangatvictor/.docker/run/docker.sock >> ~/.zshrc

    replace the .zsshrc with your respective file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search