Model answers for 4 Docker questions
Typical round: concepts, Dockerfile review, troubleshooting
Q: How do you make a Docker build faster? A: Order instructions from least to most frequently changing so cached layers are reused: copy dependency files and install packages before copying source code. Use a .dockerignore to keep the build context small.
Q: What is a multi-stage build? A: A Dockerfile with several FROM stages, where you compile in a full build image and copy only the output into a slim runtime image. It shrinks image size and removes build tools from production.
Q: CMD vs ENTRYPOINT? A: ENTRYPOINT sets the executable that always runs; CMD sets default arguments that can be overridden at docker run. A common pattern is ENTRYPOINT for the binary and CMD for default flags.
Q: A container exits right after starting. How do you debug it? A: Check docker ps -a for the exit code, read docker logs, inspect the command and environment with docker inspect, and start an interactive shell from the same image to run the command manually.