Tip of the day: running Flagr Docker image on a M1 mac

Submitted by Frederic Marand on
Docker and Rosetta 2 logos

After almost one year with an Apple Silicon macBook, I eventually got my first actual problem caused by the architecture : trying to deploy the Flagr Open Source feature flags service, the docker deployment failed like with an image error. The fix turned out to be fairly simple:

The problem

One deploys Flagr initially by pulling an image and running it, to avoid the complexity of having to build it. From their Get Started page:

# Start the docker container


$ docker pull ghcr.io/openflagr/flagr
$ docker run -it -p 18000:18000 ghcr.io/openflagr/flagr

# Open the Flagr UI
$ open localhost:18000

The pull step went through just fine, but when trying the docker run an issue appeared:

$ docker run -it -p 18000:18000 ghcr.io/openflagr/flagr
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
docker: Error response from daemon: platform linux/arm64/v8 not supported.
ERRO[0000] error waiting for container: context canceled
$

Diagnostic

The error is fairly clear: without specifying an architecture, the download image is the one built for linux/amd64 and our M1 on macOS, needs an image for darwin/arm64. How do we specify this to docker ?

Turns out docker has an argument for this: --platform=darwin/amd64, to be used with Docker commands, by passing it before the name of the image:

docker pull --platform=darwin/arm64 ghcr.io/openflagr/flagr
docker run -it -p 18000:18000 --platform=darwin/arm64  ghcr.io/openflagr/flagr

However, this is not really better, although the error is different:

$ docker run -it -p 18000:18000 --platform=darwin/arm64  ghcr.io/openflagr/flagr
Unable to find image 'ghcr.io/openflagr/flagr:latest' locally
8d68b8be8eac: Exists
aa19e9ea6d59: Exists
docker: Error response from daemon: platform darwin/arm64 not supported.
See 'docker run --help'.
$

After some more checks, it appears flagr:1.1, currently the latest version, is not built for arm64. OK, but then we should be able to run using the Rosetta 2 emulation.

How can we can check if Rosetta is running ? Solution is with something like pgrep oahd (but it could be a false positive) or something safer like ps -e | grep oahd.

And of course I had never needed it yet :facepalm .

The solution

So let's install Rosetta 2:

$ softwareupdate --install-rosetta
I have read and agree to the terms of the software license agreement. A list of Apple SLAs may be found here: http://www.apple.com/legal/sla/
Type A and press return to agree: a
2022-10-21 17:24:32.524 softwareupdate[38332:520724] Package Authoring Error: 012-40509: Package reference com.apple.pkg.RosettaUpdateAuto is missing installKBytes attribute
Install of Rosetta 2 finished successfully
$

At this point we should now be able to run x84-64 (amd64) binaries, including that Flagr image:

$ docker pull --platform=linux/amd64 ghcr.io/openflagr/flagr
Using default tag: latest
aa19e9ea6d59: Exists
8d68b8be8eac: Exists
ghcr.io/openflagr/flagr:latest
$ docker run -it -p 18000:18000 --platform=linux/amd64  ghcr.io/openflagr/flagr
INFO[0000] Serving flagr at http://[::]:18000

Problem solved ! We now have a working Flagr server on the M1 macBook.