containers / podman-desktop

Podman Desktop - A graphical tool for developing on containers and Kubernetes
https://podman-desktop.io
Apache License 2.0
4.22k stars 264 forks source link

Cannot cross build image to the target arm64 platform on amd64 host system when using RUN command in the containerfile #7004

Open odockal opened 3 weeks ago

odockal commented 3 weeks ago

Bug description

I am trying to cross build an image from containerfile on amd64 host system to arm64 target platform. getting error:

Screenshot_20240429_165700

Operating system

Windows 10

Installation Method

Installer from website/GitHub releases

Version

1.10.0

Steps to reproduce

  1. Be on intel based machine, ie. amd64 arch.
  2. Start up podman machine
  3. Create a containerfile to build, ie:
    FROM ghcr.io/linuxcontainers/alpine
    RUN echo "Hello world!"

    or

    FROM fedora:39
    RUN dnf install -y vim
  4. Build an image using this containerfile -> pick up the file, context folder and image name
  5. Choose to build image using ARM64 platform
  6. Assert: image is built Actual:
    Uploading the build context from C:\Users\podmanqe\fedora_images...Can take a while...
    Building image-local-fedora...
    STEP 1/2: FROM fedora:39
    Resolving %!q(<nil>) to docker.io (enforced by caller)
    Trying to pull docker.io/library/fedora:39...
    Getting image source signatures
    Copying blob sha256:22bb2152dc6386a1d2269ed00e37f29db25a6003edd92e1e785aace8b93f657c
    Copying config sha256:40a32ce358f786e152609d399c331d807270e10783a70bfaaf654ac32fbb72a5
    Writing manifest to image destination
    STEP 2/2: RUN dnf install -y vim
    exec container process `/bin/sh`: Exec format error
    Error:building at STEP "RUN dnf install -y vim": while running runtime: exit status 1

Relevant log output

Uploading the build context from C:\Users\podmanqe\fedora_images...Can take a while...
Building image-local-fedora...
STEP 1/2: FROM fedora:39
Resolving %!q(<nil>) to docker.io (enforced by caller)
Trying to pull docker.io/library/fedora:39...
Getting image source signatures
Copying blob sha256:22bb2152dc6386a1d2269ed00e37f29db25a6003edd92e1e785aace8b93f657c
Copying config sha256:40a32ce358f786e152609d399c331d807270e10783a70bfaaf654ac32fbb72a5
Writing manifest to image destination
STEP 2/2: RUN dnf install -y vim
exec container process `/bin/sh`: Exec format error
Error:building at STEP "RUN dnf install -y vim": while running runtime: exit status 1

Additional context

No response

benoitf commented 3 weeks ago

could you please be sure to clean all the build cache before, I saw some bugs using buildah sometimes

podman system prune

odockal commented 3 weeks ago

Does not seem like the case.

cdrage commented 3 weeks ago

could you please be sure to clean all the build cache before, I saw some bugs using buildah sometimes

podman system prune

Looks like this is happening too on our "other extension" side. There is an issue posted regarding another error @odockal got.

When I did podman machine reset and recreated the machine it looks to have fixed it.

benoitf commented 3 weeks ago

I just tried on a macOS amd64 and it works

https://github.com/containers/podman-desktop/assets/436777/12942213-978e-4613-a908-39db418a9498

(it says aarch64 while I'm on a amd64 system)

cdrage commented 3 weeks ago

@odockal looks like it may be this issue: https://github.com/containers/podman/issues/19961 as I was able to replicate it myself.

macOS and Linux is it working fine.

Windows is unfortunately having issues building an arm image. It looks like a caching issue as per the last comment.

Only way is to reset the podman machine and try again it seems.

benoitf commented 3 weeks ago

in all case issue is not in podman desktop codebase so I would not make it as a blocker for 1.10.x

odockal commented 3 weeks ago

@cdrage @benoitf I believe that you are right. It might be out of control of podman desktop. although, if people will start build cross-platform images on windows, they gonna hit this. I have never managed on windows amd64 host to build image with target arch64 platform nor via podman desktop nor using cli.

Update: I am not saying this is blocking release, though.

odockal commented 3 weeks ago

Containerfile:

FROM fedora:39
RUN arch

cli command: podman build -t fedora-arch --platform=linux/amd64 .

Result is the same for pd and podman cli: Error: building at STEP "RUN arch": while running runtime: exit status 1

odockal commented 3 weeks ago

@cdrage @benoitf The workaround suggested in the last comment make it work!

odockal commented 3 weeks ago

Workaround:

podman machine ssh
curl https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh > qemu-binfmt-conf.sh
chmod +x qemu-binfmt-conf.sh
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
sudo ./qemu-binfmt-conf.sh --qemu-suffix "-static" --qemu-path "/usr/bin" -p yes
exit
podman build -t fedora-arch --platform=linux/arm64 .
STEP 1/2: FROM fedora:39
STEP 2/2: RUN arch
aarch64
COMMIT fedora-arch
--> 0b4b09c0e454
Successfully tagged localhost/fedora-arch:latest
0b4b09c0e45452807989881064fa4b94741246e2bc39ab29a91e38b2700256f7
benoitf commented 3 weeks ago

OK so definitely a podman issue. We might ask them to see if they can fix it in the podman machine

benoitf commented 3 weeks ago

I think it requires fixes but only in the machine

benoitf commented 3 weeks ago

https://github.com/containers/podman-machine-wsl-os/blob/main/.cirrus.yml probably a patch there

benoitf commented 3 weeks ago

Adding os/Windows label to the issue as it's windows specific ( on macOS it works as expected)

benoitf commented 2 weeks ago

removing 1.10.1 milestone and created https://github.com/containers/podman-machine-wsl-os/issues/1