moby / buildkit

concurrent, cache-efficient, and Dockerfile-agnostic builder toolkit
https://github.com/moby/moby/issues/34227
Apache License 2.0
8.12k stars 1.15k forks source link

--mount=type=bind,from= don't use local image first #1688

Open RammusXu opened 4 years ago

RammusXu commented 4 years ago

Question

I expect --mount=type=bind,from=pc will use my local image but it seems to fetch dockerhub. Is it possible to configure this?

Steps

Build a image named: pc

 docker build -t pc docker/package-cache \
    --build-arg BULIDID=1 \
    --cache-from type=local,src=./pc-cache \
    --cache-to type=local,dest=./pc-cache

Build another image to mount pc source

RUN --mount=type=bind,target=/root/cache,from=pc,source=/root/cache \
    ls -lat /root/cache 

docker build -t demo --progress=plain .

 #9 CANCELED
------
 > FROM docker.io/library/pc:latest:
------
failed to solve: rpc error: code = Unknown desc = failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

Other

$ docker images
REPOSITORY                                            TAG                 IMAGE ID            CREATED             SIZE
pc                                                    latest              891848118e39        17 hours ago        42.7MB
$ docker builder ls 
NAME/NODE  DRIVER/ENDPOINT             STATUS  PLATFORMS
rammus *   docker-container                    
  rammus0  unix:///var/run/docker.sock running linux/amd64, linux/arm64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
tonistiigi commented 4 years ago

Is this Docker or buildx? It is expected that if you use docker-container driver you can't refer to the local docker instance images as container driver runs in an isolated environment and doesn't use docker storage.

RammusXu commented 4 years ago

@tonistiigi It's supposed to be buildx since I used export DOCKER_BUILDKIT=1.

so, is it possible to pass resource from a local docker image more elegant?

For now I can do

Mount a directory in a temporary docker container and copy resources.

docker run --rm -v $PWD/my-cache:/root/my-cache pc sh -c "cp -r /root/cache/* /root/my-cache"

Pass copied resource as a read only mount in Dockerfile

RUN --mount=type=bind,target=/root/cache,source=my-cache \
    ls -lat /root/cache