nix2container icon indicating copy to clipboard operation
nix2container copied to clipboard

Example defaults to amd64 architecture

Open jmgilman opened this issue 3 years ago • 1 comments

Running the example in the README:

> nix run github:nlewo/nix2container#examples.bash.copyToDockerDaemon  
> docker run -it bash:2bq5nc0g665z2ixfv1lzypxki5cqjf42 
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error

This is running on a Macbook M1 Pro. I've tried parsing through some of the logic and I'm not familiar enough with the backend to understand why it's defaulting to this architecture. Any ideas?

jmgilman avatar Jul 22 '22 17:07 jmgilman

Currently, nix2container.buildImage doesn't expose an attribute to specify the architecture.

To support this feature, we would need to do two things:

  • expose an attribute in nix2container functions. The architecture would be then written in the produced image JSON file. This should be quite easy to implemented
  • use this attribute in the Nix Skopeo transport: i don't know (yet) how to specify it but this should not be a big deal.

Regarding the default architecture value, i think it's Skopeo that decides it (but i don't know how).

I think it would be nice to support different architectures but i only have a x86-linux machine, so i won't be able to test this feature (expecting via the CI but that's time consuming...).

nlewo avatar Jul 27 '22 07:07 nlewo

This issue shouldn't be closed. I'm still getting the wrong architecture being generated on the M1 platform.

❯ docker run -it bash:2bq5nc0g665z2ixfv1lzypxki5cqjf42 
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
standard_init_linux.go:228: exec user process caused: exec format error

jmgilman avatar Sep 15 '22 23:09 jmgilman

I apologize for my oversight, the issue is fixed, I just didn't account for the fact that the image being built was targeting darwin.

jmgilman avatar Sep 16 '22 22:09 jmgilman

@jmgilman No problem. I always like to see an issue being closed ;)

nlewo avatar Sep 18 '22 07:09 nlewo

I'm building a docker image from an and Linux machine and a M1 user is having the error that @jmgilman posted. Is there an option to build to both architectures? does this need to be build on a M1 CI?

hrajchert avatar Aug 18 '23 18:08 hrajchert

If Nix is running on an M1, it's going to attempt to build the binaries for the native M1 architecture/OS. If you then copy this to the Docker daemon running on an M1, you'll run into a host of exec errors because it's expecting a completely different format (ELF, to be exact). You need to run Nix in an ARM Linux machine to get the correct results.

jmgilman avatar Aug 18 '23 20:08 jmgilman

You need to run Nix in an ARM Linux machine to get the correct results.

I'm recognizing some GH handles here and presuming some more context I have, I can also suggest to try std|paisano --for x86_64-linux ... It was precisely made to build a x86_64-linux image more ergonomically on another machine. Due to lack of an M1 in my hands, it hasn't been thoroughly tested, but it was designed to locally (e.g. on a M1) use native toolchain to execute all actions (such as copyToDockerDaemon) while at the same time still building an x86_64-linux image.

blaggacao avatar Aug 19 '23 23:08 blaggacao