Cli: Unable to use COPY --from , docker build trying to pull image

Created on 10 Dec 2018  Â·  16Comments  Â·  Source: docker/cli

Description
Docker file

FROM [imageName] AS builder

# Step that fails
COPY --from=builder [file] [destination]

When I try to build the docker file with the above, I get this error:
invalid from flag value builder: pull access denied for builder, repository does not exist or may require 'docker login'

I have imageName already pulled locally and I have access to the private repo it lives in. But it seems as though I just have trouble in the copy line. I am running version: 18.09.0

Steps to reproduce the issue:

  1. Run docker version 18.09.0
  2. Create docker file with above contents
  3. Run docker build . -t [image tag]

Describe the results you received:
Seems as though that syntax does not work. I receive the following error:
invalid from flag value [alias name] regardless of what alias I assign. I tried using the index 0 but that threw another error stating:
invalid from flag value 0: refers to current build stage
When I try 1 as the index, I get an out of bounds error which is expected
Describe the results you expected:

I am expecting that the build will work with the syntax --from=builder
Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client: Docker Engine - Community
 Version:           18.09.0
 API version:       1.39
 Go version:        go1.10.4
 Git commit:        4d60db4
 Built:             Wed Nov  7 00:47:43 2018
 OS/Arch:           darwin/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.0
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.4
  Git commit:       4d60db4
  Built:            Wed Nov  7 00:55:00 2018
  OS/Arch:          linux/amd64
  Experimental:     true

Output of docker info:

Containers: 27
 Running: 10
 Paused: 0
 Stopped: 17
Images: 685
Server Version: 18.09.0
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 local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.952GiB
Name: linuxkit-025000000001
ID: KFZT:ZJLY:SIQK:KB2Y:UOWM:KQRU:PDYG:N2O6:CJUI:7CVO:FNO7:TPVK
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 25
 Goroutines: 52
 System Time: 2018-12-10T16:07:48.76739092Z
 EventsListeners: 2
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Additional environment details (AWS, VirtualBox, physical, etc.):
Running on a mac
I noticed this works on our CI which uses version 17 of docker

arebuilder aredistribution platfordesktop

Most helpful comment

You need to have a second stage to use COPY --from you can not point --from to the same stage you are currently changing.

All 16 comments

You need to have a second stage to use COPY --from you can not point --from to the same stage you are currently changing.

Note that you can also get this error with a true multistage build if you delete a prior stage of the build (say with docker rm $(docker ps -f status=exited -q)) while the remaining stages are still building.

This can be a very frustrating mistake to make because it also deletes the cache so you have to start all over again 😢

@cnrmck Not with buildkit

@tonistiigi What specifically is "Not with buildkit"?

I am having the same error with COPY --from line.
I'm new to Docker, would appreciate some help.
Not sure what @tonistiigi means by needing to have a second stage.

My docker file:

`
FROM node:latest

RUN mkdir -p /src/app/

WORKDIR /src/app
ENV PATH /src/app/node_modules/.bin:$PATH

COPY package.json /src/app/

RUN npm install
RUN npm install react-scripts -g

ADD src /src/app/src
ADD public /src/app/public

COPY . /src/app
RUN npm run build

FROM nginx:1.13.12-alpine
COPY --from=build /src/app/build /share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]`

What specifically is "Not with buildkit"?

Buildkit is isolated and you can't interfere with the running build by deleting containers or images.

@triusis92

You need to do FROM node:latest AS build on first line

@tonistiigi thank you, that worked perfectly

I'm having a similar issue. An MWE Dockerfile:

FROM erlang:22.0 AS build
COPY ./a_file  /

FROM python:3.7-alpine
COPY --from=bulid /a_file .

docker build -t [tag] . with or without --pull yields the following error at the last step:
invalid from flag value bulid: pull access denied for bulid, repository does not exist or may require 'docker login'

docker version output:

Client:
 Version:           18.09.6
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        481bc77
 Built:             Sat May  4 02:35:27 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.6
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       481bc77
  Built:            Sat May  4 01:59:36 2019
  OS/Arch:          linux/amd64
  Experimental:     false

I'm running Ubuntu 16.04.6 LTS

@adnilsson --from=build not --from=bulid :)

@adnilsson and @tonistiigi this really helped me! I had the wrong name just now, too! 😹

I am having the similar issue with:

COPY --chown=1000 --from=build /opt/conda/. $CONDA_DIR

The error says: invalid from flag value build: pull access denied for build, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Could you please help me solve this? Thanks!

@anna-codefresh
My guess would be that _/scala-hello-world-test/target/scala-2.12/scala-hello-world-sample-app_2.12-1.0.jar_ does not exist inside the build. If you would just comment out the last line and build the image it builds correctly. If you are just trying to test a hello world app you can easily create a scala file with simple code and run it inside the container.

I found this guide to be helpful: https://linuxacademy.com/guide/11919-using-docker-for-scala/

@adnilsson --from=build not --from=bulid :)

oh my god, I had literally same typo, and couldn't figure out what the problem was. Thanks

FROM        scratch
COPY --from=builder [file] [destination]

@tonistiigi thank you, that worked perfectly

Can you please share how you fixed?

FROM node:8.9.1

RUN mkdir -p /data/nodeapp
WORKDIR /data/nodeapp

RUN npm install --silent --progress=false -g [email protected]

COPY package.json /data/nodeapp/

RUN yarn global add http-server

COPY . /data/nodeapp/

ENV deploymentEnv dev
RUN npm install --silent
COPY . ./
RUN npm run build

FROM nginx:stable-alpine
COPY --from=build /data/nodeapp/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

this is my file content

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stevenengler picture stevenengler  Â·  3Comments

kinghuang picture kinghuang  Â·  4Comments

loeffel-io picture loeffel-io  Â·  4Comments

zopyx picture zopyx  Â·  4Comments

bryanhuntesl picture bryanhuntesl  Â·  3Comments