Skip to main content

How to Build Fly Locally With Docker for Mac

In my recent side projet, I’ve been deploying to fly.io and really enjoying it. It’s fairly easy to get setup. And it supports my preferred workflow of deploying my changes early and often.

I have run into a few snags though. Fly.io builds your project into a docker image and deploys containers for you. That process is mostly seamless when it works. But sometimes it fails, and you need to debug.

By default, fly builds your docker images in the cloud. This is convient and preferred most of the time. But when I wanted to test some changes to my build, I wanted to try building locally using Docker Desktop.

This should be easy. The fly cli is quite nice. And there is a flag to build locally.

fly deploy --build-only --local-only

This failed saying it couldn’t find Docker.

> fly deploy --build-only --local-only
==> Verifying app config
Validating /Users/polotek/src/harembase/fly.toml
Platform: machines
✓ Configuration is valid
--> Verified app config
==> Building image
Error: failed to fetch an image or build from source: docker is unavailable to build the deployment image

I spent quite a bit of time googling for the problem here. You can also run fly doctor --verbose to get some info. (If you run this in your fly app folder, it will show more info not relevant to this topic.)

> fly doctor --verbose
Testing authentication token... PASSED
Testing flyctl agent... PASSED
Testing local Docker instance... Nope
    (We got: failed pinging docker instance: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?)
    This is fine, we'll use a remote builder.
Pinging WireGuard gateway (give us a sec)... PASSED
No app provided; skipping app specific checks

I found various forum posts discussing this problem. The folks at fly have spent a lot of time investigating some deep technical issues. I appreciate that work, but ultimately none of it seems to reflect my problem. And the issue felt simpler to me. Fly couldn’t find docker. Why not? Where is it looking?

Eventually I found the answer on stackoverflow. It turns out that things have settled pretty recently to a basic config setting. By default, Docker Desktop installs the socket for the daemon in a non-global space. Usually in your personal user folder, e.g. ~/.docker/run/docker.sock. But other tools expect the docker daemon socket to be available in a standard location, e.g. /var/run/docker.sock

As of this writing, Docker Deskstop has added a recommended way to enable the standard location. In the Docker Desktop dashboard, got to Settings > Advanced and enable “Allow the default Docker socket to be used”.

Screenshot of settings page in Docker for Mac. Advanced tab selected. Content shows the setting referenced above.

Docker for Mac settings screen

This will require your system password and restart. Then you should be able to see the docker socket in the standard place. And fly will be able to see it! Hopefully the next person who’s banging their head against this will have an easier time.