Docker cache-from not all layers being run if no files have changed

Viewed 323

I've added a simple repo that recreates this issue: https://github.com/cgreening/docker-cache-problem

We have a very simple Dockerfile.

To speed up our builds we're using the --cache-from directive and using a previous build as a cache.

We're seeing some weird behaviour where if the files have not changed the lines after the COPY line are not being run.

RUN yarn && yarn build

Does not seem to get executed so when the application tries to start node_modules is missing.

FROM node

RUN mkdir /app
COPY . /app

WORKDIR /app
RUN yarn && yarn build

ENTRYPOINT ["yarn", "start"]

We're deploying to Kubernetes but I can pull the image locally and see that the files are missing:

# docker run -it --entrypoint /bin/bash gcr.io/XXXXX
root@3561a9cdab6e:/app# ls
DEVELOPING.md  Dockerfile  Makefile  README.md  admin-tools  app.dev.yaml  jest.config.js  package.json  src  tailwind.config.js  tools  tsconfig.json  tslint.json  yarn.lock
root@3561a9cdab6e:/app#

Edit:

I've managed to recreate the problem outside of our build system.

Initial build:

DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:a .  --build-arg BUILDKIT_INLINE_CACHE=1
docker push gcr.io/XXX/test:a

All works - node_modules and build folder are there:

Clean up docker as if we starting from scratch like on the build system

docker system prune -a

Do another build:

DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:b . --cache-from gcr.io/XXX/test:a --build-arg BUILDKIT_INLINE_CACHE=1
docker push gcr.io/XXX/test:a

Everything is still fine.

Clean up docker as if we starting from scratch like on the build system

docker system prune -a

Do a third build:

DOCKER_BUILDKIT=1 docker build -t gcr.io/XXX/test:c . --cache-from gcr.io/XXX/test:b --build-arg BUILDKIT_INLINE_CACHE=1

Files are missing!

docker run -it --entrypoint /bin/bash gcr.io/topo-wme-dev-d725ec6e/test:c
root@d07f6f1d3b12:/app# ls
DEVELOPING.md  Dockerfile  Makefile  README.md  admin-tools  app.dev.yaml  coverage  jest.config.js  package.json  src  tailwind.config.js  tools  tsconfig.json  tslint.json  yarn.lock

No node_modules or build folder.

0 Answers
Related