Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#3246·kaniko

Cache not found from package installs in previous multistage stages

Author: joeautyCreated Jul 11, 2024Updated Jun 2, 2025
Labelskind/bugarea/multi-stage buildsarea/cachingpriority/p1area/apt

Actual behavior Apt install commands are not being cached running Kaniko as a Kubernetes job, making image builds very slow

Expected behavior Cache layer hit/being found since, as far as I can tell, there should be no filesystem differences between builds

To Reproduce Steps to reproduce the behavior:

  1. Run the Kubernetes job:
image: gcr.io/kaniko-project/executor:v1.23.1-debug
command: ["/kaniko/executor"]
args:
  - "--context=/workspace/build/buildkite/${BUILDKITE_ORGANIZATION_SLUG}/${BUILDKITE_PIPELINE_SLUG}"
  - "--destination=[repo URL]"
  - "--cache-repo=[cache repo URL]"
  - "--cache=true"
  - "--cleanup=true"
  - "--ignore-path=.git"

Additional Information

  • Dockerfile
bash
# ---- BASE IMAGE ----
FROM ruby:3.3.3-slim-bullseye as base-image

ENV INSTALL_PATH /data/go
ENV GETTEXT_LOCALES_PATH  $INSTALL_PATH/config/gettext_locales
ENV GETTEXT_CLIENT_LOCALES_PATH $INSTALL_PATH/client/locales
WORKDIR $INSTALL_PATH

RUN apt-get update && apt-get install -y libicu-dev libpq-dev python3-pip python-dev build-essential --no-install-recommends && apt-get clean \
  && pip install --upgrade setuptools pip \
  && pip install awscli \
  && gem update --system 3.5.13 \
  && gem install bundler:2.5.13

# ---- BUILD DEPENDENCIES ----
FROM base-image as build-dependencies

ENV INSTALL_PATH /data/go
ENV NODE_MAJOR 18
WORKDIR $INSTALL_PATH

SHELL ["/bin/bash", "-lc"]

RUN apt-get update && apt-get install -y curl gnupg ca-certificates --no-install-recommends && apt-get clean
COPY ./.tool-versions $INSTALL_PATH

The apt-get update && apt-get install -y curl gnupg ca-certificates --no-install-recommends && apt-get clean command is not being loaded from cache, all other commands up to this point are loaded from cache. The logs show:

No cached layer found for cmd RUN apt-get update && apt-get install -y curl gnupg ca-certificates --no-install-recommends && apt-get clean

This same Dockerfile built in Docker makes use of the cache, making build times much faster.

Triage Notes for the Maintainers

Description Yes/No
Please check if this a new feature you are proposing
  • - [ ]
Please check if the build works in docker but not in kaniko
  • - [x]
Please check if this error is seen when you use --cache flag
  • - [x]
Please check if your dockerfile is a multistage dockerfile
  • - [x]

Source: GoogleContainerTools/kaniko

View original on GitHubView discussion on GitHub