Skip to content

findBaseImage in dockerfileUtils.ts does not handle buildkit automatic variables in layers name #275

Closed

Description

@sylver

Giving a simple Dockerfile example, leveraging the TARGETARCH automatic variable provided in the global scope by buildkit:

ARG APT_FLAGS="-y -qq --no-install-recommends --no-install-suggests"

FROM node AS base-arm64
ONBUILD ARG PACKAGES="\
  build-essential \
  python3 \
"

FROM node AS base-amd64
ONBUILD ARG PACKAGES=""

FROM base-${TARGETARCH} AS base

 apt-get install ${APT_FLAGS} ${PACKAGES}

# do common stuff

The TARGETARCH global scope variable (Nor for that matter any others) does not seem available for replacement when searching the base image in the findBaseImage function called by internalGetImageBuildInfoFromDockerfile during the build

export function findBaseImage(dockerfile: Dockerfile, buildArgs: Record<string, string>, target: string | undefined) {

in our case ending up returning the value base- which does not exist and then fails:

[1197 ms] Start: Run: docker inspect --type image base-
[3802 ms] Error fetching image details: No manifest found for docker.io/library/base-.
[3802 ms] Start: Run: docker pull base-
invalid reference format
[3903 ms] []
[3903 ms] Error response from daemon: no such image: base-: invalid reference format

Also, another issue I found along the way when inspecting available values, parsing does not handle quoted values (nor multilines). Based on the previous Dockerfile example, we end up in the provided replacements to replaceVariables function with:

  // [...]
  { instruction: 'ARG', name: 'APT_FLAGS', value: '"-y' },
  { instruction: 'ARG', name: 'PACKAGES', value: '"\\' },
  // [...]

Activity

  1. added
    bug
    on Nov 9, 2022
  2. sylver commented on Nov 9, 2022

    @sylver
    Author

    Christof Marti (@chrmarti) Additionally, trying to find a workaround in the meantime, I just noticed that parsing of variables with replacements (ie. ${FOO:-bar}) does not work either.

    With something like:

    ARG ARCH=${TARGETARCH:-amd64}
    
    # [...]
    
    FROM base-${ARCH} AS base
    
    # [...]

    The CLI complains:

    [63348916 ms] Start: Run: docker inspect --type image base-:-amd64}
    [63351485 ms] Error fetching image details: No manifest found for docker.io/library/base-:-amd64}.
    [63351485 ms] Start: Run: docker pull base-:-amd64}
    invalid reference format
    [63352081 ms] []
    [63352081 ms] Error response from daemon: no such image: base-:-amd64}: invalid reference format
    
    [63352081 ms] Command failed: docker inspect --type image base-:-amd64}
    
  3. rawler commented on Feb 19, 2026

    @rawler

    Any triage or plans for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions