cache-from in buildkit returns invalid character error

Open
#3,572 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
docker, go

Research direction

Start by reproducing the two Docker builds with the shown Dockerfile, especially the second command using --cache-from=base:latest. Then trace BuildKit's cache-from handling after image metadata is loaded. Done means the invalid-character failure is explained and corrected or the expected behavior is documented with a regression test.

Written by the indexing model from the issue text.

Description

Hi!

I found strange behavior in this scenario.

I have python script (main.py):

print("Hello, World!")

Some requirements.txt:

python-dateutil==2.8.1

and Dockerfile:

# syntax=docker/dockerfile:1

FROM python:3-slim as base

RUN --mount=type=bind,target=./requirements.txt,src=./requirements.txt \
    --mount=type=cache,mode=0755,target=/root/.cache/pip \
    pip install -r requirements.txt

FROM base as main

COPY . /app
CMD ["python", "/app/main.py"]

I build first version with command and everything works fine:

docker build -t base --target base --build-arg BUILDKIT_INLINE_CACHE=1 .

After that I want to release a new version and reuse cache:

python-dateutil==2.8.2
docker build -t base --target base --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from=base:latest .

And I get this output:

[+] Building 1.2s (5/5) FINISHED
 => [internal] load .dockerignore                                                                                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                 0.0s 
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                            0.0s 
 => => transferring dockerfile: 340B                                                                                                                                                                                                                                            0.0s 
 => resolve image config for docker.io/docker/dockerfile:1                                                                                                                                                                                                                      0.5s 
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:d2d74ff22a0e47b21f4bbde337e2ac4cd0a02a2226ef79264878db3dc7e87df8                                                                                                                                                 0.0s
 => => resolve docker.io/docker/dockerfile:1@sha256:d2d74ff22a0e47b21f4bbde337e2ac4cd0a02a2226ef79264878db3dc7e87df8                                                                                                                                                            0.0s 
 => [internal] load metadata for docker.io/library/python:3-slim                                                                                                                                                                                                                0.5s
invalid character 'c' looking for beginning of value

With --progress=plain it looks like this:

#5 [internal] load metadata for docker.io/library/python:3-slim
#5 sha256:1d53a8326d1210addccb4bc5ed043a5dc9dc3d4d221b85e1b898fd379832ee7b
#5 DONE 1.3s
invalid character 'c' looking for beginning of value

Is it correct behavior? Or I didn't understand BuildKit caching system?

Dominant language
Go
Stars
10.3k
Forks
1.5k
Avg merge
1d 23h
Merged PRs (30d)
48

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from moby/buildkit

All issues in moby/buildkit

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.