The Build Is Slow, So Let's Just Add --no-cache to CI?
CI Docker builds crept to 11 minutes and once shipped a stale dependency. A teammate wants --no-cache on every build. Defend what you actually do first.
Answer key reviewed by Branko Petric
Read first: Writing Dockerfiles: Best Practices for Small, Fast Images
Your decision
Docker builds in CI are taking 11 minutes and sometimes ship stale dependencies. A teammate says just add --no-cache to every build so we always get a clean image and stop debugging cache weirdness. What do you do, and why?
The situation
Your CI pipeline builds a Docker image on every push. Over the last few months the build time crept from about 3 minutes to 11, and last week a deploy shipped an image that still had an old version of a library everyone thought had been upgraded. After that nobody trusts the cache anymore.
Context
The service is a Node app built from a simple Dockerfile. Line 4 is COPY . . and the RUN npm ci step comes after it, so every push copies the whole working tree in before dependencies are installed. The base image is referenced by a floating tag rather than a digest. A teammate posts in the channel: just add --no-cache to every CI build, then we always get a clean image and we can stop debugging cache weirdness.
Worked interview answers
- Docker Scenario Based Interview Questions: Diagnose First, Then Defend the Fix
Docker scenario based interview questions, worked: a 1.6GB image, --no-cache, a mounted Docker socket, exit code 137, a secret in a layer and container DNS.
- Scenario Based DevOps Interview Questions, With Worked Answers
Scenario based DevOps interview questions for Linux, Docker, CI/CD, Git and AWS, with first commands, the interviewer's pushback, and weak vs strong answers.
Related challenges
- 1.6GB Docker Image, 8-Minute Builds. Add Runners?
Your image is huge and every code change rebuilds from scratch. A teammate wants to just add more CI runners. Defend how you actually fix it.
- The Container Needs Docker, So Mount the Socket and Run --privileged?
A CI job needs to build images and a teammate wants to bind-mount the Docker socket and run --privileged to fix permission errors. Defend the safe approach.
- Tests Pass Locally, Fail in CI. Just Retry?
Your suite is green on your laptop but red in CI. A teammate wants to add a retry and re-run until green. Defend what you actually do.
- The Pipeline Is Slow. Skip Tests to Ship?
A 40-minute pipeline is blocking releases. A teammate wants to skip the test stage to ship faster. Defend your call.