cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open ldm810 opened this issue 7 years ago • 27 comments

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

ldm810 avatar Dec 10 '18 16:12 ldm810

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

tonistiigi avatar Dec 11 '18 10:12 tonistiigi

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 😢

connormcmk avatar May 10 '19 21:05 connormcmk

@cnrmck Not with buildkit

tonistiigi avatar May 10 '19 21:05 tonistiigi

@tonistiigi What specifically is "Not with buildkit"?

connormcmk avatar May 14 '19 15:05 connormcmk

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;"]`

triusis92 avatar May 28 '19 21:05 triusis92

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 avatar May 28 '19 21:05 tonistiigi

@tonistiigi thank you, that worked perfectly

triusis92 avatar May 28 '19 21:05 triusis92

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 avatar Jun 12 '19 07:06 adnilsson

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

tonistiigi avatar Jun 12 '19 17:06 tonistiigi

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

kevincantu avatar Jun 20 '19 06:06 kevincantu

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!

SimronThapa avatar Apr 01 '20 00:04 SimronThapa

@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/

triusis92 avatar Apr 02 '20 22:04 triusis92

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

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

sergiynikon avatar Aug 08 '20 20:08 sergiynikon

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

steelx avatar Aug 30 '20 10:08 steelx

@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

anitha-hanumanthaiah avatar Sep 29 '20 06:09 anitha-hanumanthaiah

@anitha-hanumanthaiah , I think it can solve to you:

FROM node:8.9.1 as build

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;"]

pethersonmoreno avatar Mar 24 '21 13:03 pethersonmoreno

Hey guys! Could someone help with this? Every time, I get pull access denied:

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

FROM python:3.9.7 as build

RUN mkdir -p /opt/psmqtt
WORKDIR /opt/psmqtt
RUN mkdir -p /var/log/psmqtt

ENV VIRTUAL_ENV=/opt/psmqtt
RUN python -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

COPY requirements.txt .
RUN pip install -r requirements.txt

RUN useradd --create-home psmqtt
USER psmqtt

VOLUME ["/opt/psmqtt/conf"]

ENV PSMQTTCONFIG="/opt/psmqtt/conf/psmqtt.conf"

COPY --from=build --chown=psmqtt /opt/psmqtt $VIRTUAL_ENV

ENV PATH="$VIRTUAL_ENV/bin:$PATH"
CMD python psmqtt.py

What I do wrong?

SAOPP avatar Sep 18 '21 10:09 SAOPP

Guys i solved it, added second FROM, but got another trouble with the image as well. Python can't find file location but it's another issue... I think at my dockerfile...

SAOPP avatar Sep 18 '21 11:09 SAOPP

The same issue: failed to compute cache key: failed to walk /var/lib/docker/tmp/buildkit-mount048400018/app/dist: lstat /var/lib/docker/tmp/buildkit-mount048400018/app/dist: no such file or directory. How to fix I need to fix those issues. This is my dockerfile content

FROM node:latest as build
WORKDIR /usr/local/app
COPY package*.json .
COPY ./ /usr/local/app/
RUN rm -rf node_modules
RUN npm install
RUN npm run build
FROM nginx:latest
Copy ./nginx/nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/local/app

COPY --from=build /app/dist/Angular13Crud/ /usr/share/nginx/html
EXPOSE 80

Abbasunity avatar Jan 03 '22 12:01 Abbasunity