A Dockerfile has `RUN cd /app` followed by `RUN npm install` and it fails. Why?
BeginnerScenarioImage design and Dockerfile decisions
Answer
Situation read → Each RUN starts a fresh shell; cd does not persist across instructions.
What I'd do → Use WORKDIR /app (which also creates the directory) and then RUN npm install. Or chain: RUN cd /app && npm install.
Why → Only filesystem changes persist between layers, not shell state such as cwd or exported variables.
Interview tip → Same reason RUN export FOO=bar is useless; use ENV.
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