An image is a read-only, layered template built from a Dockerfile; a container is a running instance of it with its own writable layer. For testing, Docker gives reproducible environments: the same browser, runtime and dependencies locally and in CI, disposable databases and services, and easy parallel isolation.
Full answer with examplesInterview questions / DevOps
Docker Interview Questions
Docker questions for QA focus on reproducible test environments, running browsers in containers and composing dependent services.
4 questions · 1 beginner· 2 intermediate· 1 advanced
beginner questions
intermediate questions
How would you write a Dockerfile for a test runner?
intermediate 2–5 yrs
Start from a pinned base image that already has the browsers or runtime you need, copy dependency manifests first and install so the layer is cached, then copy the test code. Run as a non-root user, keep secrets out of the image, pass config at runtime, and write reports to a mounted directory.
Full answer with examplesHow would you use Docker Compose to spin up a test environment?
intermediate 2–5 yrs
Define the app, its database and dependencies, and the test runner as services in compose.yaml. Use healthchecks with depends_on condition service_healthy so tests start only when services are ready, address services by name on the Compose network, and run with docker compose up --abort-on-container-exit.
Full answer with examplesadvanced questions
Testcontainers is a library that starts real dependencies such as Postgres, Kafka or Redis in throwaway Docker containers from test code, with wait strategies and random ports. Use it for integration tests that need real behaviour; trade-offs are Docker availability in CI, startup cost and container reuse strategy.
Full answer with examples