What is the difference between `ARG` and `ENV`, and when does each matter?
BeginnerScenarioImage design and Dockerfile decisions
Answer
Situation read → One is build-time, the other persists into the running container.
What I'd do → Use ARG for build parameters (ARG APP_VERSION) and ENV for runtime variables. An ARG declared before FROM is only usable in FROM lines unless redeclared after it. Convert when needed: ENV VERSION=$APP_VERSION.
Why → ARG values appear in docker history and do not exist at runtime; ENV values are visible to anyone with docker inspect.
Interview tip → Neither is a safe place for secrets.
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