Should you run `chmod`/`chown` in a separate `RUN` after `COPY`?
IntermediateScenarioImage design and Dockerfile decisions
Answer
Situation read → A separate RUN chown -R duplicates all copied files into a new layer, doubling size.
What I'd do →
COPY --chown=app:app --chmod=0755 entrypoint.sh /usr/local/bin/
COPY --chown=app:app . /app
Why → The metadata is set at copy time, with no duplicated layer.
Interview tip → --chmod requires BuildKit; it is the default builder since Docker 23.
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