docker / buildx

Docker CLI plugin for extended build capabilities with BuildKit
Apache License 2.0
3.6k stars 485 forks source link

ARG support in COPY #2352

Open FernandoMiguel opened 6 years ago

FernandoMiguel commented 6 years ago

Description

Steps to reproduce the issue:

  1. docker build --build-arg IMAGE_BUILDER_NAME=node-builder-ms-xxxx --file Dockerfile/Dockerfile .

Describe the results you received: invalid from flag value ${IMAGE_BUILDER_NAME}: invalid reference format: repository name must be lowercase

Describe the results you expected: Successfully built fe978fd298a

Output of docker version:

Client:
 Version:   18.03.0-ce
 API version:   1.37
 Go version:    go1.9.4
 Git commit:    0520e24
 Built: Wed Mar 21 23:06:22 2018
 OS/Arch:   darwin/amd64
 Experimental:  false
 Orchestrator:  swarm

Server:
 Engine:
  Version:  18.03.0-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.4
  Git commit:   0520e24
  Built:    Wed Mar 21 23:14:32 2018
  OS/Arch:  linux/amd64
  Experimental: true

Output of docker info:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 38
Server Version: 18.03.0-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host ipvlan macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfd04396dc68220d1cecbe686a6cc3aa5ce3667c
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.855GiB
Name: linuxkit-025000000001
ID: MWH6:QH5X:TT3F:ITI2:2C22:XQN3:2E3H:M4GK:HAZH:
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
HTTP Proxy: docker.for.mac.http.internal:3128
HTTPS Proxy: docker.for.mac.http.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false```

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

FROM node:8-alpine ARG IMAGE_BUILDER_NAME COPY --from=${IMAGE_BUILDER_NAME} /src/dist /app/dist

szymonpk commented 6 years ago

Hacky workaround, as discussed on the slack:

ARG IMAGE_BUILDER_NAME
FROM ${IMAGE_BUILDER_NAME} as builder
FROM node:8-alpine

<code...>

COPY --from=builder /src/dist /app/dist

It would be nice to have ARG evaluation in COPY.

hackel commented 6 years ago

FYI—the ARG used in FROM must come before all the FROM lines. Took me way too long to figure this out!

https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact

filipopo commented 4 days ago

+1