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

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

Closed
UltWolf opened this issue Jul 3, 2019 · 7 comments
Closed

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

UltWolf opened this issue Jul 3, 2019 · 7 comments

Comments

@UltWolf
Copy link

UltWolf commented Jul 3, 2019

Description
I have a Dockerfile like this:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build-env
WORKDIR /app 

COPY CostsAnalyse/*.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out
 
WORKDIR /app
COPY --from=build-env /app/out/ .
CMD dotnet CostsAnalyse.dll 

and when i`m run COPY --from=build-env /app/out/ . i have been get the error:
invalid from flag value build-env: pull access denied for build-env, repository does not exist or may require 'docker login'

Steps to reproduce the issue:

  1. Run docker version 18.09.2
  2. Create docker file with above contents
  3. Run docker build .

Describe the results you received:

i get the error: invalid from flag value build-env: pull access denied for build-env, repository does not exist or may require 'docker login', after running COPY --from=build-env /app/out/ .

Describe the results you expected:
I am expecting that the build will work with the syntax --from=build .

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Output of docker info:

Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 45
Server Version: 18.09.2
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 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: 9754871865f7fe2f4e74d43e2fc7ccd237edcbce
runc version: 09c8266bf2fcf9519a651b04ae54c967b9ab86ec
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.442GiB
Name: linuxkit-00155daca30a
ID: DHFO:KJHS:JNS7:MFZL:ZCSB:REFE:XSV6:S6HC:OVGA:F3VT:4PA3:K6RS
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
 File Descriptors: 22
 Goroutines: 47
 System Time: 2019-07-03T12:41:07.6438807Z
 EventsListeners: 1
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

Additional environment details (AWS, VirtualBox, physical, etc.):
Running on Windows 10.
Circle CLI build that assemble without any error.

@thaJeztah
Copy link
Member

Looks like your COPY --from is in the same build stage; it's still inside the build-dev stage

@thaJeztah
Copy link
Member

You probably want to add a new FROM above the second WORKDIR to start a new buildstage for the final image.

I'll close this issue, because I don't think there's a bug here, but feel free to continue the conversation

@UltWolf
Copy link
Author

UltWolf commented Jul 4, 2019

But why then build on the https://circleci.com is okay?
изображение
Info docker:

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 17.09.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 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: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
 apparmor
Kernel Version: 4.4.0-96-generic
Operating System: Ubuntu 14.04.5 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.305GiB
Name: default-d664688d-0647-4a33-ada8-f31a7d35c347
ID: H4I5:ZTAM:GNQK:AM3G:HF4X:RFAK:U67G:GHDB:L4S3:EBKB:Y7Z2:QPXP
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

It`s can be problem in machine or windows?

@thaJeztah
Copy link
Member

Hm interesting; I can confirm it worked on Docker 17.09, but that's not by design: the build-env stage is not finished yet at that point, so cannot be referenced, in which case --from=build-env should be looking for an image reference by that name.

Older versions of Docker failed to detect this situation, and just went ahead. Docker 17.09 seems to use build-env as "everything we did so far in the build-env stage", and copy from that;

docker build -t myimage -<<'EOF'
FROM busybox AS build-env
WORKDIR /app
RUN mkdir -p out && echo foo > out/CostsAnalyse.dll


WORKDIR /app
COPY --from=build-env /app/out/ .
EOF

Which copies the file from the current stage (or "build-env");

docker run --rm myimage ls -la /app
total 16
drwxr-xr-x    1 root     root          4096 Jul  4 13:06 .
drwxr-xr-x    1 root     root          4096 Jul  4 13:18 ..
-rw-r--r--    1 root     root             4 Jul  4 13:06 CostsAnalyse.dll
drwxr-xr-x    2 root     root          4096 Jul  4 13:06 out

Given that we're still inside the build-env stage, that Dockerfile would be roughly the
equivalent of:

FROM busybox AS build-env
WORKDIR /app
RUN mkdir -p out && echo foo > out/CostsAnalyse.dll
RUN cp -r /app/out/* .

Note that current versions of Docker with buildkit enabled will produce a more useful error message;

DOCKER_BUILDKIT=1 docker build -t myimage -<<'EOF'
FROM busybox AS build-env
WORKDIR /app
RUN mkdir -p out && echo foo > out/CostsAnalyse.dll


WORKDIR /app
COPY --from=build-env /app/out/ .
EOF

Running the above produces:

[+] Building 0.2s (2/2) FINISHED                                                                                                                                                             
 => [internal] load build definition from Dockerfile                                                                                                                                    0.1s
 => => transferring dockerfile: 184B                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                       0.2s
 => => transferring context: 2B                                                                                                                                                         0.0s
failed to create LLB definition: circular dependency detected on stage: build-env

@UltWolf
Copy link
Author

UltWolf commented Jul 5, 2019

Oh, but Windows doesn't support this function yet.
And it's very sad.
Thanks for your help, and detailed answers.

@thaJeztah
Copy link
Member

Correct, BuildKit is unfortunately not yet supported on Windows, but for this Dockerfile to work, it's not needed; if you intended to make a multi-stage build, you need to add aFROM line

@thaJeztah
Copy link
Member

Well, BuildKit is not supported for Windows containers/images; I see you're running docker desktop with Linux images;

Kernel Version: 4.9.125-linuxkit

So buildkit should work

chrysn added a commit to chrysn-pull-requests/riotdocker that referenced this issue Aug 25, 2021
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

3 participants