Jenkins: Cannot connect to the Docker daemon on Mac

I’m running Jenkins for MacOS (using Homebrew) and Docker Desktop on Mac.
When I try to build docker image for Python app from Jenkins pipeline, the following error is reported:

+ docker build -t <docker image name>:41 .
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Jenkinsfile snippet:

pipeline {
    agent none
    stages {
        ...
            stage("Build Docker Image") {
            agent {
                docker { image 'docker:24.0.5' }
            }
            environment {
        HOME = "${env.WORKSPACE}"
        }
            steps {
               script {
                dockerImage = docker.build("<docker image name>:${env.BUILD_ID}")
               }
            }
        }
        ...
    }
}

In previous stages, docker containers are successfully used.
I found similar case here Jenkins: Can't connect to Docker daemon - Stack Overflow for CentOS. I assume that I need to add my user to docker group (even if I can already run docker commands without sudo) but when I run dscl . list /groups command (the command which outputs all groups on Mac) I cannot find group named docker. I have also tried to run the following in Jenkins pipeline:

+ whoami
whoami: unknown uid 501

Then I ran id command from my terminal to compare the uid and this is the uid of my user which I’m currently using and managing Jenkins.
Thanks in advance for any help.

Last, I created group docker:

sudo dseditgroup -o create docker

and added mentioned user to docker group:

sudo dseditgroup -o edit -a <user> -t user docker

and restared Docker Desktop and Jenkins. The issue persists.

I fixed this issue by changing “agent” to “any” in the Jenkins pipeline stage:

pipeline {
    agent none
    stages {
        ...
            stage("Build Docker Image") {
            agent any
            environment {
        HOME = "${env.WORKSPACE}"
        }
            steps {
               script {
                dockerImage = docker.build("<docker image name>:${env.BUILD_ID}")
               }
            }
        }
        ...
    }
}

docker:24.0.5 docker image was not working due to docker-in-docker scenario. Now, the docker image is successfully built on my local docker engine.