<#22602 docker_build_args with Target References n...
# github-notifications
q
#22602 docker_build_args with Target References not working Issue created by ademariag ## Bug Report Pants does not properly support target references when passed as
extra_build_args
in Docker image targets. When users try to pass target addresses as build arguments, Pants fails to resolve them to the actual built Docker image tags, causing build failures. ## Reproducing the Issue Demo available in https://github.com/ademariag/pants-demo-bugs/tree/main/docker_args_test This directory demonstrates the problem with a concrete example. The following configuration currently fails: BUILD file: docker_image( name="base", source="Dockerfile.base", # FROM ubuntu ) docker_image( name="base2", source="Dockerfile.base2", # FROM alpine ) docker_image( name="main", source="Dockerfile", extra_build_args=[ "BASE_IMAGE=:base2" # Target reference - would not resolve properly ] ) Dockerfile: ARG BASE_IMAGE=:base FROM ${BASE_IMAGE} RUN echo "using ${BASE_IMAGE}" The
BASE_IMAGE=:base2
argument is not being resolved to the actual Docker image tag of the built
:base2
target, causing the
FROM ${BASE_IMAGE}
instruction to fail. ## Expected Behavior The target reference
:base2
in the
extra_build_args
should be resolved to the actual Docker image tag produced by building the
:base
target (e.g.,
sha256:abc123...
or a tagged name), allowing the Dockerfile's
FROM ${BASE_IMAGE}
instruction to work correctly. This would enable powerful Docker image composition patterns where one Docker image can reference another Pants-built Docker image as its base image through build arguments. ## Current Error When running: pants package docker_args_test:main The build fails because
${BASE_IMAGE}
resolves to the literal string
:base
instead of the actual built Docker image identifier, causing Docker's
FROM
instruction to fail with an invalid image reference. ## Impact This limitation prevents users from: • Creating hierarchical Docker image dependencies within Pants • Dynamically selecting base images through build arguments • Composing complex Docker build pipelines where images depend on other Pants-built images ## Workaround Currently, users must hardcode image tags or use external tooling to pass the correct image references, defeating the purpose of Pants' dependency management for Docker images. Pants version pants_version = "2.26.1" OS Linux Additional info Add any other information about the problem here, such as attachments or links to gists, if relevant. pantsbuild/pants