You must pass a database password into an image at build time to download a private package. How?
IntermediateScenarioImage design and Dockerfile decisions
Answer
Situation read → ARG/ENV values persist in image history; never use them for secrets.
What I'd do → Use BuildKit secrets:
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker build --secret id=npmrc,src=$HOME/.npmrc .
Why → The secret is mounted in tmpfs for that RUN only and never lands in a layer or docker history.
Interview tip → Also mention --mount=type=ssh for private git clones.
More on Image design and Dockerfile decisions
A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?BeginnerYou need to run `apt-get install` in a Dockerfile. How do you write it so the layer stays small and cache-safe?BeginnerWhen would you pick `COPY` over `ADD`?BeginnerA service must run a startup script and then the app. Should you use `CMD`, `ENTRYPOINT`, or both?BeginnerYour Docker build re-installs all Python dependencies on every code change. Fix it.BeginnerProduct asks for a container that runs both nginx and a Python app. What do you say?Beginner