Docker Interview Questions on Images, Storage and Runtime Behaviour
Docker interviews test whether you understand what comes from an image, what belongs to a container and what persists separately. These original questions follow a recreated container whose new image contains updated files, while an existing non-empty volume still presents older content at the same path. The case explains mount visibility without deleting data or running Docker.
Topic: Containers: Docker & Podman in IT Infrastructure · Interview preparation
Quick answer: Docker interviews test whether you understand what comes from an image, what belongs to a container and what persists separately. These original questions follow a recreated container whose new image contains updated files, while an existing non-empty volume still presents older content at the same path. The case explains mount visibility without deleting data or running Docker. It also covers Dockerfiles, networking, Compose, security and troubleshooting, with documented limits rather than fabricated command output or the promise that a container runs unchanged on every host.
Key takeaways
- An image and a container have different lifecycles.
- A non-empty mounted volume can obscure image files.
- Stopping a container differs from removing it.
- EXPOSE documents a port rather than publishing it.
- Protect daemon access, build secrets and persistent data.
Table of Contents
- How do images, containers and virtual machines differ?
- Why can a recreated container show older files than its new image?
- What persists when a container stops or is removed?
- What should Dockerfile and build answers establish?
- How do networking, Compose and orchestration fit?
- Which security decisions should a Docker answer include?
- How would you troubleshoot the mounted-file case safely?
- References
How do images, containers and virtual machines differ?
1. What is a Docker image? It is a packaged filesystem and configuration used to create a container under a compatible runtime. A tag is a reference that can change, so retain appropriate image identity for reproducibility.
2. What is a container? It is an execution instance with its configured process, isolation, writable layer and mounts. Docker’s container-run guide distinguishes container storage from filesystem mounts.
3. Is a container a small VM? It uses a different isolation model. Linux containers rely on a compatible Linux kernel, which may be supplied through a VM on another host platform. Packaging does not eliminate CPU-architecture, kernel or runtime compatibility requirements.
Why can a recreated container show older files than its new image?
The fictional application mounts an existing non-empty named volume at /app/data. The new image contains a revised example file under that path, but the mounted view still shows the volume’s earlier file.
4. Is this proof that the new image was not used? No. Docker’s volume guide explains that a non-empty volume mounted over existing container files obscures those files. Image identity and the effective mounted view are separate facts.
5. What should you inspect before changing anything? Identify the container’s image, mount destination, volume identity and data owner. Determine whether the path contains durable application data or a replaceable example. Do not remove a volume merely to make a new image’s file visible.
| Object | Supplied content | Mounted visibility |
|---|---|---|
| New image path | Revised example | Obscured by the supplied mount |
| Existing non-empty volume | Earlier file | Visible under the stated mount |
| Container | Recreated instance | Does not reset the separate volume |
What persists when a container stops or is removed?
6. Does stopping erase the writable layer? Stopping differs from removing the container. Data in that layer remains associated with the existing container, while removing it removes that layer. Persistent mounts have their own lifecycle.
7. How do a named volume and bind mount differ? Docker manages a volume’s storage, while a bind mount refers to a chosen host path under the supported environment. Both need permissions, ownership and recovery planning.
8. Does Compose down remove every volume by default? Docker’s Compose-down reference documents default container and network removal, a separate volume-removal option and protection for external volumes. Anonymous-volume reuse also differs from named volumes.
9. Is an empty volume identical to the supplied non-empty one? No. Docker documents default copying of existing image-path contents into an empty mounted volume, subject to relevant options. Establish the actual state before predicting visibility.
| State or action | Distinction | Review concern |
|---|---|---|
| Stop container | Different from removal | Process state and restart intent |
| Remove container | Writable-layer lifecycle changes | Data kept only there |
| Retain named volume | Independent data remains | Ownership and backup |
| Non-empty mounted volume | Image files are obscured | Actual content source |
What should Dockerfile and build answers establish?
10. How do RUN and CMD differ? RUN performs a build-stage action; CMD supplies a default runtime command or arguments. Docker’s Dockerfile reference documents their forms and interaction with ENTRYPOINT.
11. Can ENTRYPOINT be overridden? Runtime configuration can override the entrypoint under supported options. Explain exec versus shell form and the chosen invocation rather than saying an entrypoint is unchangeable.
12. What do multistage builds provide? They separate build stages and allow selected outputs to enter a later image. This can reduce unnecessary runtime contents, but requires explicit copying and dependency review.
13. Does EXPOSE open a host port? No. It documents an intended container port; publishing and network policy are separate configuration decisions.
How do networking, Compose and orchestration fit?
14. What does bridge networking provide? It supplies a supported container-network arrangement under the runtime’s configuration. Reachability still depends on addresses, bindings, publishing and applicable policy.
15. Why can an application work inside a container but not from the host? Inspect the listening address, container port, published mapping and network path. Do not infer which layer failed from one symptom alone.
16. What is Compose? It describes and manages a multi-service application through supported project configuration. It does not by itself establish cluster scheduling, high availability or production suitability.
17. How do Docker and Kubernetes relate? Docker includes container tooling and runtime capabilities; Kubernetes orchestrates workloads through its supported runtime interfaces. They are not interchangeable names for the same layer.
Which security decisions should a Docker answer include?
18. Where should build credentials go? Docker’s build-secrets guide warns against passing build secrets through ordinary build arguments or environment variables that persist in image contents. Use an approved scoped mechanism and inspect what the build writes.
19. Why restrict daemon control? Docker’s security guide explains the authority of the daemon and the importance of trusted access, with rootless and other supported configurations requiring their own scope review.
Review image provenance, dependencies, unnecessary privilege, mounts and runtime identity. A small image is not automatically safe, and container isolation does not authorize access to the host or another workload.
How would you troubleshoot the mounted-file case safely?
20. What is your recommendation? Keep the volume intact and identify which content source the application uses. Compare reviewed image identity with the supplied mount configuration and expected application-data contract.
If the release needs a data migration, treat it as a separate approved operation with compatibility and recovery planning. If it only needs a new default example, decide how defaults should be managed without overwriting owned data. Recreating the container is not a universal data-upgrade mechanism.
Walk through image creation, container creation, mount selection and application startup. State the observation that distinguishes an old image from an existing-volume view. That explains the lifecycle error without reaching immediately for destructive cleanup.
Related reading: Virtualization interview questions; Kubernetes interview questions.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0