I have a Dockerfile that caches a RUN npm ci when executed locally with docker binary, but fails when running with nerdctl. Other layers are cached properly. Here's the relevant part of docker output:
[+] Building 1.8s (14/14) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 1.39kB 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 112B 0.0s
=> [internal] load metadata for docker.io/library/node:18-bullseye-slim 1.0s
=> [1/9] FROM docker.io/library/node:18-bullseye-slim@sha256:a6b88857a85c692ded74bee86c9d42630c646f8a77267c0a281fb726ae54cdba 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 295.92kB 0.0s
=> CACHED [2/9] RUN apt-get update && apt-get install -y locales openssl curl ca-certificates gpg make --no-install-recommends && localed 0.0s
=> CACHED [3/9] RUN curl -fsSL https://pgp.mongodb.com/server-4.4.asc | gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg --dearmor & 0.0s
=> CACHED [4/9] RUN apt-get install ibgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb -y 0.0s
=> CACHED [5/9] WORKDIR /opt/app 0.0s
=> CACHED [6/9] COPY package.json . 0.0s
=> CACHED [7/9] COPY package-lock.json . 0.0s
=> CACHED [8/9] RUN npm ci 0.0s
=> [9/9] COPY . . 0.3s
=> exporting to image 0.1s
=> => exporting layers
All layers, even before this one, are cached. Nothing strange to see here.
And this is what I get remotely (running in a Jenkins agent in k8s) for approximately the same lines:
#7 [4/9] RUN apt-get install ibgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb -y
#7 CACHED
#8 [2/9] RUN apt-get update && apt-get install -y locales openssl curl ca-certificates gpg make --no-install-recommends && localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 && rm -rf /var/lib/apt/lists/*
#8 CACHED
#9 [6/9] COPY package.json .
#9 CACHED
#10 [3/9] RUN curl -fsSL https://pgp.mongodb.com/server-4.4.asc | gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg --dearmor && echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list && apt-get update && apt-get install -y mongodb-org-tools mongodb-org-shell
#10 CACHED
#11 [7/9] COPY package-lock.json .
#11 CACHED
#12 [8/9] RUN npm ci
#12 21.07
#12 21.07 added 212 packages, and audited 213 packages in 21s
#12 21.07
#12 21.07 41 packages are looking for funding
#12 21.07 run `npm fund` for details
#12 21.10
#12 21.10 6 vulnerabilities (5 moderate, 1 critical)
#12 21.10
#12 21.10 To address issues that do not require attention, run:
#12 21.10 npm audit fix
#12 21.10
#12 21.10 To address all issues (including breaking changes), run:
#12 21.10 npm audit fix --force
#12 21.10
#12 21.10 Run `npm audit` for details.
#12 21.10 npm notice
#12 21.10 npm notice New patch version of npm available! 10.2.3 -> 10.2.5
#12 21.10 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v10.2.5>
#12 21.10 npm notice Run `npm install -g [email protected]` to update!
#12 21.10 npm notice
#12 DONE 24.7s
As you can see, the layer is not cached. The previous RUN layer, the one running apt-get is cached properly. The COPY layers are all good. I do not understand why then is the RUN npm ci a problem for Nerdctl.
Here's the Dockerfile producing all this:
FROM node:18-bullseye-slim
## Update system and install deps
RUN apt-get update && apt-get install -y locales openssl curl ca-certificates gpg make --no-install-recommends \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
&& rm -rf /var/lib/apt/lists/*
## Install Mongo shell
RUN curl -fsSL https://pgp.mongodb.com/server-4.4.asc | \
gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg \
--dearmor \
&& echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list \
&& apt-get update \
&& apt-get install -y mongodb-org-tools mongodb-org-shell
## Cypress dependencies
RUN apt-get install ibgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libnss3 libxss1 libasound2 libxtst6 xauth xvfb -y
## Get e2e app set up
WORKDIR /opt/app
COPY package.json .
COPY package-lock.json .
RUN npm ci
COPY . .
## Environment setup
## Redacted a few env variables here, but this is already past the RUN layer in question.
## Electron is finicky
ENV ELECTRON_EXTRA_LAUNCH_ARGS='--disable-gpu'
ENV TERM=linux
## Finally, execute the make all
CMD ["npm", "run", "run:ci:short"]