Podman — Cannot connect to the Docker daemon error on macOS
A quick post on enabling
podman.sock on macOS
I use Podman to build container images and have been pretty happy with it. Podman has worked great for me on my macOS, and because it has the same commands as the original Docker CLI, so the switch hasn't been difficult at all.
However, recently when trying to scan the container image for vulnerabilities using Trivy, I got the error below
unable to inspect the image (nginx-web:1.0.1-feat.1): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Thanks to this gist, I found out that, On macOS, Podman CLI tries to connect to the socket but for some unknown reason, macOS does not expose the
podman.socket . Thus the error.
To resolve this, first, get the list of the
podman sockets on your machine using the below command
$ podman system connection list
The next step is to redirect the ssh connectivity so that
podman.sock can be connected. Notice that port 50865 and user 501 should be changed as per the output of the previous command.
ssh -fnNT -L/tmp/podman.sock:/run/user/501/podman/podman.sock -i ~/.ssh/podman-machine-default ssh://core@localhost:50865 -o StreamLocalBindUnlink=yes
Finally, export the
DOCKER_HOST variable to the path you set in the above command. In my case, it was set to
Now you should be able to run any Podman/Trivy commands on the local machine without issues.