InterviewStack.io LogoInterviewStack.io

Docker Image Building and Optimization Questions

Practical knowledge of creating Docker images: writing Dockerfiles, multi-stage builds, optimizing image layers for size and performance, understanding base images, managing dependencies, and best practices for production-ready images. Ability to troubleshoot image build issues and explain decisions made in Dockerfile design.

HardTechnical
51 practiced
You built an image using multi-stage builds but at runtime the container fails with an ImportError or a missing shared library. Provide a step-by-step debugging plan using Docker tooling to identify which stage or layer omitted the dependency. Include commands such as docker history, docker run --rm -it, docker image save | tar -tvf, dive, and how you would fix the problem without unnecessarily bloating the final image.
HardTechnical
73 practiced
Discuss the trade-offs involved in squashing image layers (for example using --squash or tools like docker-slim) versus keeping many granular layers. Address rebuild performance, caching benefits, image size, transparency for security scanners, ability to apply patches or incremental updates, and debugging complexity. Give two scenarios where squashing makes sense and two where it is harmful.
HardTechnical
51 practiced
CI Docker builds are being killed due to out-of-memory conditions during compilation of native modules. List possible mitigation strategies: increasing runner memory or swap, lowering parallelism, splitting build workloads into smaller stages, using more memory-efficient toolchains, and pulling prebuilt artifacts from an artifact repository. For each mitigation, explain trade-offs and when to prefer it.
EasyTechnical
65 practiced
Compare COPY and ADD in Dockerfiles. Provide at least two concrete examples where ADD behaves differently from COPY (for example, remote URL retrieval and auto-extracting local tar archives). Explain why COPY is generally preferred in production Dockerfiles and what security or build-context implications arise from using ADD.
HardTechnical
57 practiced
For each language ecosystem (Go, Java, Python, Node.js), explain the implications of choosing distroless, scratch, or alpine base images for runtime. Consider compatibility, debugging experience, binary dependencies, musl vs glibc differences, and best practices to enable observability such as health checks and logs. Provide a recommended base for each language and justify your choice.

Unlock Full Question Bank

Get access to hundreds of Docker Image Building and Optimization interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.