Docker & Containerization - Interview Q&A
1. What is the difference between a Docker image and a Docker container?
A Docker image is a read-only blueprint that contains the application code, dependencies,
environment, and configuration needed to run an app. A Docker container is a runtime instance of
that image its the actual isolated process running based on the image.
2. How does Docker achieve isolation between containers?
Docker uses Linux namespaces and control groups (cgroups). Namespaces isolate system
resources like PIDs, network interfaces, and users. Cgroups limit CPU, memory, and other
resources. Docker also uses UnionFS for layered filesystems and provides virtual networking.
3. What is the purpose of a Dockerfile, and can you name some common instructions used in
it?
A Dockerfile is a script that defines how to build a Docker image. Common instructions include:
FROM, WORKDIR, COPY, RUN, CMD, EXPOSE, and ENTRYPOINT.
4. Whats the difference between CMD and ENTRYPOINT in a Dockerfile? Can they be used
together?
CMD sets default arguments. ENTRYPOINT defines the main executable. They can be used
together: ENTRYPOINT runs the app, CMD passes default args.
5. What is the difference between a bind mount and a Docker volume? When would you use
each?
Bind mounts map a host directory into a container and are useful for development. Volumes are
managed by Docker, stored internally, and better for production.
6. How does networking work between two containers?
Containers on the same Docker network (usually a custom bridge) can communicate using
container names. Docker provides DNS for name resolution inside the network.
7. What is a multi-stage build in Docker? Why is it useful?
Multi-stage builds use multiple FROM statements to optimize final images by excluding build tools
and only copying necessary artifacts. This reduces image size.
8. How do you debug a container that keeps crashing?
Use `docker logs` to check output, `docker inspect` to see config and exit codes, run with interactive
shell (`/bin/sh`) to explore, or override CMD temporarily.
9. What are the benefits of using Docker in a CI/CD pipeline?
Docker ensures consistency across environments, supports automation of build/test/deploy steps,
enables isolated testing, and provides reusable, versioned artifacts.
10. What is Docker Compose and how does it simplify working with multiple containers?
Docker Compose uses a YAML file to define and manage multi-container apps. It simplifies
networking, orchestration, and lifecycle management with a single command.