Building arm Docker images from Windows doesn't work on target machine

Viewed 411

I am building a linux/arm/v7 image from Windows 10 to be run on a Raspberry Pi running a 32 bit OS.

Dockerfile

FROM nginx:1.19.8-alpine

CMD nginx -g 'daemon off;'

Build and push

On Windows, I run:

docker buildx build --platform linux/arm/v7 -t harvzor/nginx-multi-arch-cross-compile --push .

Running docker inspect image harvzor/nginx-multi-arch-cross-compile on the built image produces:

[
    {
        // ...
        "Architecture": "arm",
        "Os": "linux",
        // ...
    }
]

Docker Hub identifies the image as arm based.

https://hub.docker.com/repository/docker/harvzor/nginx-multi-arch-cross-compile

Pull and run (error!)

I then pull down that same image on the Raspberry Pi and try running it, this is the output:

$ docker run harvzor/nginx-multi-arch-cross-compile
standard_init_linux.go:211: exec user process caused "exec format error"
failed to resize tty, using default size

Details

My image is based off of nginx:1.19.8-alpine, which has a linux/arm/v7 OS/ARCH.

Inspecting buildx on Windows produces:

$ docker buildx inspect 
Name:   default
Driver: docker

Nodes:
Name:      default
Endpoint:  default
Status:    running
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6

If I try running this image on Windows, it runs fine (though I think it should not since it is built for arm).

Windows Docker versions

$ docker -v
Docker version 19.03.13, build 4484c46d9d
docker buildx version
github.com/docker/buildx v0.4.2-tp-docker fb7b670b764764dc4716df3eba07ffdae4cc47b2

Questions

What am I doing wrong? Why does the image work on Windows and not the target platform?

1 Answers

I still have no idea about what was going on but Windows was for sure building for the wrong target platform.

Running this on Windows:

$ docker run harvzor/nginx-multi-arch-cross-compile@sha256:20a63dd8ee5daab206baef00bffc9bf316a93ebca452ff531c0202f6c22ee0c1 uname -m
x86_64

So clearly the wrong image was being created.

I thought I'd test for building for multiple platforms:

docker buildx build --platform linux/amd64,linux/arm/v7 -t harvzor/nginx-multi-arch-cross-compile --push .

And this time ran for linux/arm/v7:

$ docker run harvzor/nginx-multi-arch-cross-compile@sha256:64c586e218d433680dd13aa92f4e47ddd3a29147049f728b10a2b5070225d22b uname -m
armv7l

Finally the correct version has been created.

note that I'm pretty sure I also experienced this with a Rust Docker image being built by CI which also wouldn't run on my Pi!

Related