Docker image of linux/amd64 swift failing with `invalid driver name: swift-driver` on Mac M3?

Cross-posting from How to install Swift lang using Docker on linux/amd64? Getting `invalid driver name: swift-driver`? - Stack Overflow for visibility.

I saw the official Swift Dockerfile, for ubuntu:22.04, but it is not for amd64. So then I found a non-official one at swiftarm/swift, and tried installing it like this:


FROM --platform=linux/amd64 swiftarm/swift
RUN swift -v


$ docker build -f Dockerfile.swift --platform linux/amd64 . -t test-swift

[+] Building 136.4s (6/6) FINISHED                                                                                   docker:desktop-linux
=> [internal] load .dockerignore                                                                                                    0.0s
=> => transferring context: 45B                                                                                                     0.0s
=> [internal] load build definition from Dockerfile.swift                                                                           0.0s
=> => transferring dockerfile: 76B                                                                                                  0.0s
=> [internal] load metadata for                                                                     2.5s
=> [auth] swiftarm/swift:pull token for                                                                        0.0s
=> [1/2] FROM
=> => extracting ...
=> ERROR [2/2] RUN swift -v                                                                                                         0.5s
> [2/2] RUN swift -v:
0.198 error: invalid driver name: swift-driver
  1 |     FROM swiftarm/swift
  2 | >>> RUN swift -v
  3 |
ERROR: failed to solve: process "/bin/sh -c swift -v" did not complete successfully: exit code: 1
 ELIFECYCLE  Command failed with exit code 1.

It fails with:

error: invalid driver name: swift-driver

That is what I get if I tried installing swift from source in another way too. Here are the official swift releases.

I need it on linux/amd64 because I would like to host this on, which says:

The Docker image must be built for the linux/amd64 platform.

How can I get Swift building through Docker on linux/amd64? Such that swift -v doesn't throw that error?

If nothing else, what does that error invalid driver name: swift-driver mean?

I tried this as well, according to About | Swift Community Repository, but no go:

FROM --platform=linux/amd64 amd64/ubuntu:lunar

RUN apt-get update -y -q
RUN apt-get upgrade -y -q

RUN apt-get -y install curl

RUN curl -s | bash
RUN apt-get -y install swiftlang
RUN swift -v

Same error.

I am running docker build on my Mac, Apple M3 Pro Sonoma 14.1.1.

I'm not sure this is your issue, but I've ran into this error with Rosetta enabled in Docker.

UPDATE: Removed incorrect information.

1 Like

You are (quite reasonably!) confusing amd64, aka x86_64 or x64, with arm64, aka aarch64. I think the official Swift Docker image should be sufficient for your needs.

You are (quite reasonably!) confusing amd64 , aka x86_64 or x64, with arm64 , aka aarch64.

@jrose Good catch.

@lancejpollard Yes, this could be the same issue I ran into before. For me, this occurred when running Swift in an x86_64 (a.k.a amd64) Docker container with Rosetta2 enabled on an arm64 (a.k.a aarch64) Mac. Disabling Rosetta2 fixed the issue.

1 Like

Wait so what is the solution here? wants a linux/amd64 image, so what do I change? Also how does Rosetta2 relate to me, I haven't touched that?

Using this:

FROM swift:jammy as builder
RUN swift -v

I still get the same error...

So I'm not 100% sure this is the issue you are seeing, but I had the same error reported when I had Rosetta enabled locally:

This screenshot is from the Docker app which is what configures what happens when you run docker build in the terminal. Rosetta makes running amd64/x86_84 binaries faster/more efficient on Apple Silicon (though it's still pretty fast without Rosetta). I can't say I understand the underlying issue, this is just something I've ran into recently.

Disabling Rosetta fixed the issue for me, enabling me to build and run Swift in an x86_64 Docker container locally on my Apple Silicon Mac. I wasn't interacting with an external service like, so I can't speak to that.

1 Like

That fixed it, yay!!!

1 Like

Seems like we'll see a proper solution soon [CommandLine][Linux] Don't read argv from /proc/self/cmdline. by al45tair · Pull Request #71611 · apple/swift · GitHub