Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARG in COPY causes invalid reference format #3356

Closed
kale1d0code opened this issue Nov 2, 2021 · 2 comments
Closed

ARG in COPY causes invalid reference format #3356

kale1d0code opened this issue Nov 2, 2021 · 2 comments

Comments

@kale1d0code
Copy link

Description
When using a build argument to refer to a image tag to copy files from, Docker returns with the error image:$IMAGE_VERSION: invalid reference format or image:${IMAGE_VERSION}: invalid reference format

Steps to reproduce the issue:

  1. create a Dockerfile with a build argument
  2. reference this build argument in a COPY --from command
  3. try to build image

Describe the results you received:
Docker fails the build step with image:$IMAGE_VERSION: invalid reference format or image:${IMAGE_VERSION}: invalid reference format

Describe the results you expected:
for Docker to complete the build step and continue to the next

Additional information you deem important (e.g. issue happens only occasionally):
Dockerfile up to the error

FROM php:8.0-fpm-alpine
ARG COMPOSER_VERSION=1.10.23
COPY --from=composer:$COMPOSER_VERSION /usr/bin/composer /usr/local/bin/composer

Output of docker version:

Client: Docker Engine - Community
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        b485636
 Built:             Mon Oct 25 07:43:13 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.10
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       e2f740d
  Built:            Mon Oct 25 07:41:20 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 25
  Running: 3
  Paused: 0
  Stopped: 22
 Images: 225
 Server Version: 20.10.10
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.13.0-20-generic
 Operating System: Ubuntu 21.10
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 11.61GiB
 Name: HP-250-G6-Notebook-PC
 ID: BJG5:Q4RG:TTFT:WKAT:MDOO:MC4R:H74P:7YVG:7I2W:3REG:TOTM:YOMQ
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details (AWS, VirtualBox, physical, etc.):

@thaJeztah
Copy link
Member

Variable expansion in command --flags is not yet supported. Work is done to add support for some properties, but (IIRC) only for global ARG, not local ones. The docker builder uses these references to build the LLB graph, for which it needs to expand the variable, which, again, if I recall correctly, could not use a local (inside FROM) build-arg, as those could depend on environment-variables from the base image.

For your use-case, I'd recommend creating an "alias" stage, in which you use the build-arg to specify the version. For example;

# syntax=docker/dockerfile:1

ARG COMPOSER_VERSION=1.10.23

FROM composer:$COMPOSER_VERSION AS composer_binary

FROM php:8.0-fpm-alpine
COPY --from=composer_binary /usr/bin/composer /usr/local/bin/composer

@thaJeztah
Copy link
Member

Let me close this ticket, as this looks to be working as expected, but feel free to continue the conversation

bryteise added a commit to bryteise/dockerfiles that referenced this issue Jun 14, 2024
bryteise added a commit to clearlinux/dockerfiles that referenced this issue Jun 14, 2024
Note that variable expansion in --from and FROM was working oddly,
see: docker/cli#3356 (comment)
for context.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants