Skip to content

Podman doesn't resolve TARGETARCH properly in FROM and COPY --from #6964

Description

@isaac-sec

Issue Description

Podman substitutes TARGETARCH, but fails to correctly resolve dependencies that require it in the following Containerfiles:

  1. in FROM:
FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS artifacts-amd64

RUN echo "amd64" > /arch

FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS artifacts-arm64

RUN echo "arm64" > /arch

FROM artifacts-${TARGETARCH} AS artifacts

ARG TARGETARCH

ENV TARGETARCH=${TARGETARCH}
RUN echo "Hello $(cat /arch): ${TARGETARCH}"
  1. in COPY --from
FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS artifacts-amd64

RUN echo "amd64" > /arch

FROM alpine:3.23.4@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS artifacts-arm64

RUN echo "arm64" > /arch

FROM scratch AS artifacts

ARG TARGETARCH

COPY --from=artifacts-${TARGETARCH} /arch /arch

Docker correctly resolves the former, although not the latter because it doesn't support substitution in COPY --from.

Steps to reproduce the issue

Steps to reproduce the issue

  1. run podman build . --platform linux/amd64,linux/arm64 in the directory where you created the Containerfile

Describe the results you received

Depending on your host architecture, you'll see either artifacts-amd64 or artifacts-arm64 being built in both the amd64 build as well as the arm64 one instead of each of them building their respective stages.

Then the build fails with the following errors:

  • For the FROM case -- Error: [linux/arm64]: creating build container: short-name "artifacts-arm64" did not resolve to an alias and no containers-registries.conf(5) was found
  • For the COPY --from case -- Error: [linux/arm64]: COPY --from=artifacts-arm64: no stage or image found with that name

Describe the results you expected

Each build should correctly substitute TAREGTARCH so that these references work.

podman info output

host:
  arch: amd64
  buildahVersion: 1.44.0
  cdiSpecDirs:
  - /etc/cdi
  - /var/run/cdi
  cgroupControllers:
  - cpu
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-1:2.2.1-1
    path: /usr/bin/conmon
    version: 'conmon version 2.2.1, commit: c8cc2c4db27531bd4e084ce7857f73cd21ee639d'
  cpuUtilization:
    idlePercent: 96.83
    systemPercent: 0.66
    userPercent: 2.51
  cpus: 22
  databaseBackend: sqlite
  distribution:
    distribution: arch
    version: unknown
  emulatedArchitectures:
  - linux/arm
  - linux/arm64
  - linux/arm64be
  - linux/loong64
  - linux/mips
  - linux/mips64
  - linux/ppc
  - linux/ppc64
  - linux/ppc64le
  - linux/riscv32
  - linux/riscv64
  - linux/s390x
  eventLogger: journald
  freeLocks: 2002
  hostname: isaac-pc
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 7.1.2-arch3-1
  linkmode: dynamic
  logDriver: journald
  memFree: 766627840
  memTotal: 33115537408
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    defaultNetwork: podman
    dns:
      package: aardvark-dns-2.0.0-1
      path: /usr/lib/podman/aardvark-dns
      version: aardvark-dns 2.0.0
    package: netavark-2.0.0-1
    path: /usr/lib/podman/netavark
    version: netavark 2.0.0
  ociRuntime:
    name: crun
    package: crun-1.28-1
    path: /usr/bin/crun
    version: |-
      crun version 1.28-dirty
      commit: 54f16ffbefcd022bf032af768b5c5ce075c18bfc
      rundir: /run/user/1000/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +JSON_C
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-2026_06_11.a9c61ff-1
    version: |
      pasta 2026_06_11.a9c61ff
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: true
    path: /run/user/1000/podman/podman.sock
  rootlessNetworkCmd: pasta
  rootlessPortForwarder: rootlessport
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: false
  swapFree: 196608
  swapTotal: 4294963200
  uptime: 196h 27m 56.00s (Approximately 8.17 days)
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries: {}
store:
  containerStore:
    number: 19
    paused: 0
    running: 0
    stopped: 19
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev
  graphRoot: /home/isaac/.local/share/containers/storage
  graphStatus:
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Supports shifting: "false"
    Supports volatile: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 575
  runRoot: /run/user/1000/containers
  transientStore: false
  volumePath: /home/isaac/.local/share/containers/storage/volumes
version:
  APIVersion: 6.0.0
  Built: 1782770596
  BuiltTime: Tue Jun 30 01:03:16 2026
  GitCommit: a8ed4b6dd12992decf659cadfdfb3d0cb1937748
  GoVersion: go1.26.4-X:nodwarf5
  Os: linux
  OsArch: linux/amd64
  Version: 6.0.0

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

Running on Arch with the latest Podman release as of this writing.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.stale-issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions