Docker Interview Questions for AI Training Work
AI training platforms often test Docker directly, through a live coding round or a technical screen, rather than just taking a resume's word for it. These questions cover the parts of Docker that actually come up under that kind of scrutiny: Images & Layers, Networking & Volumes and Multi-stage Builds & Optimization.
Below are 10 questions split into technical, scenario, and behavioral rounds, each with a full written answer so you can see what a strong response sounds like.
Technical (5)
What's the difference between a Docker image and a container?
An image is a read-only, layered template built from a Dockerfile, containing the filesystem and configuration needed to run something. A container is a running (or stopped) instance of that image, with its own writable layer on top for any runtime changes. You can run many independent containers from the same image, each isolated from the others despite sharing the underlying image layers.
Explain how Docker's layer caching works and why instruction order in a Dockerfile matters.
Each instruction in a Dockerfile produces a layer, and Docker reuses a cached layer if that instruction and everything before it are unchanged. Putting instructions that change often, like copying application source code, after instructions that rarely change, like installing dependencies, means dependency installation stays cached across builds and only the actual code-copy layer rebuilds, which speeds up iterative builds significantly.
What's the difference between a Docker volume and a bind mount?
A volume is managed entirely by Docker and stored in Docker's own storage area, making it portable across environments and easier to back up or migrate. A bind mount maps a specific path on the host filesystem directly into the container, useful for local development when you want live changes to source code on the host to appear immediately inside the container without a rebuild.
Why would you use a multi-stage build, and what problem does it solve?
A multi-stage build lets you use one stage with a full build toolchain, like a compiler or a large SDK, to produce build artifacts, then copy only those artifacts into a lean final stage based on a minimal base image. That keeps the shipped image small and reduces its attack surface, since none of the build-time tooling, source code, or intermediate files end up in the image that actually runs in production.
What's the difference between `CMD` and `ENTRYPOINT` in a Dockerfile?
`ENTRYPOINT` defines the fixed executable a container runs and is hard to override at `docker run` time without an explicit flag. `CMD` provides default arguments that get appended to `ENTRYPOINT`, or the default command if `ENTRYPOINT` isn't set, and can be overridden simply by passing arguments to `docker run`. Combining both, a fixed `ENTRYPOINT` with a default `CMD`, is a common pattern for images meant to behave like a single command-line tool.
Scenario (3)
A container works fine locally but crashes immediately after deployment. How do you debug it?
I'd start with `docker logs` on the failed container to see the actual exit reason, since a crash-on-start almost always logs something before dying. If logs are empty, I'd check the exit code with `docker inspect`, common causes there are a missing environment variable that's present locally but not in the deploy config, or a base image mismatch between architectures, like building on ARM locally and deploying to an x86 host.
A Docker image has grown to over 2GB and deployments are slow. How would you shrink it?
I'd first check what's actually in the image with a tool like `dive`, since large images are usually explained by a small number of layers rather than being uniformly bloated. Common fixes are switching to a slim or alpine base image, using a multi-stage build to drop build tools from the final image, and cleaning up package manager caches within the same layer they were created in, since a later `rm` in a new layer doesn't shrink the image.
Two containers on the same host need to communicate, but you want them isolated from a third container. How do you set that up?
I'd put the two communicating containers on a shared user-defined Docker network, which also gives them DNS-based service discovery by container name, and leave the third container on a different network or none at all. Docker's default bridge network doesn't provide this isolation as cleanly, so a purpose-built user-defined network is the more explicit and reliable way to control which containers can reach each other.
Behavioral (2)
Tell me about a time a Docker build wasn't reproducible across environments.
A build worked on my machine but failed in CI because a base image tag like `node:18` had moved to a newer patch version between the two builds, and that patch introduced a breaking change in a transitive dependency. I pinned the base image to a specific digest instead of a floating tag, which made the build fully reproducible, and it changed how I write Dockerfiles now, always pinning versions explicitly rather than trusting a tag to stay stable.
Describe a time you had to convince a team to containerize a service that had always run directly on a VM.
The team's main worry was operational unfamiliarity with Docker, not a technical objection. I containerized one low-risk internal service first as a proof of concept, documented the exact deployment steps, and let the team see the actual failure modes and rollback process in a low-stakes setting before proposing it for anything customer-facing. Seeing it work in practice addressed the concern faster than any argument about it would have.
Knowing the answer and saying it out loud under pressure are different skills.
The Academy has free modules and mock exams to build the second one.