To fix the "cannot connect to the Docker daemon at unix:///var/run/docker.sock" error on macOS, try exporting the following:
export DOCKER_HOST=unix://$HOME/.docker/run/docker.sock
Alternatively, you can use Docker over TCP. Here's how to configure Docker Desktop to expose the Docker daemon via TCP instead of a Unix socket:
- Open Docker Desktop.
- Navigate to Settings > General.
- Enable "Expose daemon on tcp://localhost:2375 without TLS" (Note: This option exposes the Docker daemon without security, so use it cautiously).
- Save the settings and restart Docker Desktop.
After completing these steps, you can export DOCKER_HOST as follows:
export DOCKER_HOST=tcp://localhost:2375