Docker CI/CD Pipeline Interview Questions (2027)
52 Docker real-time interview questions for CI/CD: BuildKit caching, tagging by SHA, digests, scanning, SBOMs, registries and image promotion.
Docker real-time interview questions for CI/CD roles test how you use Docker inside a delivery pipeline: building images on ephemeral runners, caching layers, tagging by commit, pushing to a registry, scanning and signing, running integration tests with Compose, and promoting the same image digest from staging to production. This page has 52 numbered questions with direct answers, grouped by level, plus pipeline scenarios.
If you want container troubleshooting (exit codes, restart loops, networking failures), use our 100+ Docker scenario-based interview questions, which is the main Docker interview page on this site. For definitions, see Docker interview questions on core concepts. This page stays on one job: Docker as a step in CI/CD.
Key takeaways
- Interviewers for DevOps roles care less about
docker runflags and more about what happens to an image betweengit pushand production. - Build once, promote the same digest. Rebuilding per environment is the most common design mistake candidates describe.
- Know BuildKit features that matter on CI runners: registry cache export, cache mounts, build secrets, multi-platform builds and attestations.
- Tag images with the commit SHA for traceability; treat
latestas a convenience tag, never as a deploy reference. - Scanning, SBOMs and provenance belong in the pipeline, with a clear rule for when a finding fails the build.
Where Docker sits in a typical pipeline
| Pipeline stage | Docker work | Common interview topic |
|---|---|---|
| Build | docker buildx build with multi-stage Dockerfile | Layer caching on ephemeral runners |
| Test | Run unit tests in a build stage; integration tests with Compose | Service readiness, --wait, test isolation |
| Scan | Vulnerability scan, SBOM, provenance attestation | Fail thresholds, false positives |
| Publish | Push to Docker Hub, ECR, GHCR, Artifact Registry or Harbor | Tagging, credentials, OIDC |
| Deploy | Reference image by tag or digest in Kubernetes, ECS or Compose | Promotion, rollback, immutability |
| Cleanup | Prune runner caches, registry retention rules | Disk pressure on self-hosted runners |
Docker CI/CD questions for freshers
1. Why do CI/CD pipelines build Docker images at all?
An image packages the application with its runtime and libraries, so the artifact tested in CI is the same artifact that runs in production. That removes the "works on my machine" gap and gives every environment one deployable unit with a version.
2. What does a basic pipeline Docker step look like?
Check out the code, log in to the registry, build with a tag, then push. On a shell runner it is three commands:
echo "$REGISTRY_TOKEN" | docker login registry.example.com -u ci-bot --password-stdin
docker build -t registry.example.com/shop/api:${GIT_SHA} .
docker push registry.example.com/shop/api:${GIT_SHA}
Using --password-stdin keeps the token out of the process list and shell history.
3. Why tag images with the Git commit SHA?
The SHA links a running container back to the exact source commit. If production misbehaves, you can read the tag, open the commit and see what changed. Version tags such as 1.4.2 can be added on release, but the SHA tag is the reliable trace.
4. What is wrong with deploying the latest tag?
Tags are mutable, so latest can point to a different image tomorrow. Two nodes pulling at different times can run different code, and a rollback has no clear target. Deploy a specific tag or, better, a digest.
5. What is an image digest and why do pipelines use it?
A digest (sha256:...) is the content hash of the image manifest. It cannot be changed without changing the content, so image@sha256:... always resolves to the same bytes. Pipelines record the digest after push and pass it to later deploy stages.
6. What is a multi-stage build and why does CI care?
A multi-stage Dockerfile uses one stage with compilers and test tools and copies only the built output into a small final stage. CI gets a smaller image to push and scan, and build tools never reach production.
7. What is a .dockerignore file for in CI?
It excludes files from the build context, such as .git, node_modules, test reports and local .env files. A smaller context uploads faster to the builder, keeps secrets out of the image and stops unrelated file changes from breaking the layer cache.
8. Where do pipelines push images?
To a container registry: Docker Hub, Amazon ECR, GitHub Container Registry (ghcr.io), Google Artifact Registry, Azure Container Registry, GitLab Container Registry or a self-hosted Harbor. Our registry comparison covers the options.
9. How should registry credentials be stored in CI?
In the CI tool's secret store (GitHub Actions secrets, GitLab CI/CD variables marked masked and protected, Jenkins credentials), never in the repository or the Dockerfile. Where the cloud supports it, prefer short-lived tokens from OIDC federation over long-lived passwords.
10. Why do CI builds sometimes ignore the layer cache?
Hosted runners start empty, so there is no local cache from the previous run. Also, any change to an early instruction (or to files copied early) invalidates every later layer. Order the Dockerfile so dependency files are copied and installed before the application source.
11. How do you run unit tests during an image build?
Add a test stage in the Dockerfile that runs the test command, and build it with --target test in CI. If tests fail, the build fails. The production stage does not depend on the test stage, so test tools stay out of the final image.
12. What is Docker Compose used for in a pipeline?
Starting the app with its dependencies (database, cache, queue) for integration tests on the runner. One command brings the stack up, tests run against it, and docker compose down -v removes it, volumes included.
13. What does docker compose up --wait do?
It starts services detached and waits until they are running and healthy (for services with a health check) before returning. That avoids flaky tests caused by connecting to a database that is still starting. See the docker compose up reference.
14. What is Docker-in-Docker and what is the alternative?
Docker-in-Docker (DinD) runs a Docker daemon inside a privileged CI container so jobs can build images. The alternatives are mounting the host socket (fast but gives the job root-equivalent access to the host) or using a remote or rootless BuildKit builder. Each trades isolation against speed.
Docker CI/CD questions for 2 to 5 years of experience
15. What is BuildKit and why does it matter in CI?
BuildKit is the default builder in current Docker Engine releases. It builds independent stages in parallel, supports cache import and export, cache mounts, build secrets, SSH forwarding and multi-platform output. Most CI speed and security techniques rely on it.
16. How do you keep layer cache between runs on ephemeral runners?
Export the cache to a durable backend and import it on the next run. Buildx supports registry, local, GitHub Actions (type=gha), S3 and Azure Blob cache backends:
docker buildx build \
--cache-from type=registry,ref=registry.example.com/shop/api:buildcache \
--cache-to type=registry,ref=registry.example.com/shop/api:buildcache,mode=max \
-t registry.example.com/shop/api:${GIT_SHA} --push .
mode=max exports layers from intermediate stages too, which helps multi-stage builds. Details are in the Docker cache backends docs. More tactics are in 12 ways to speed up Docker builds in CI/CD.
17. What is a cache mount?
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt keeps a package manager cache across builds without putting it in a layer. It speeds up dependency installs when the requirements file changes. On ephemeral runners the mount is only useful if the builder itself persists.
18. How do you pass a secret to a build without leaking it into the image?
Use a build secret, not ARG or ENV, because build args are visible in image history. The secret is mounted only for one RUN instruction:
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker buildx build --secret id=npmrc,src=$HOME/.npmrc -t app:ci .
19. How do you build one image for amd64 and arm64?
Use docker buildx build --platform linux/amd64,linux/arm64 --push. Buildx produces a multi-platform image index, and each node pulls the variant for its architecture. Emulation through QEMU works but is slow for compiled languages; native builder nodes per architecture or cross-compilation in the build stage are faster.
20. What are SBOM and provenance attestations?
An SBOM lists the packages inside the image. Provenance records how and where it was built (builder, source, build parameters). Buildx can attach both to the image with --sbom=true and --provenance=mode=max. See Docker build attestations.
21. Where does image scanning go in the pipeline?
After the build and before the push to a production repository, and again on a schedule for images already in the registry, because new CVEs are published after you build. Tools include Docker Scout, Trivy, Grype and registry-native scanners in ECR, GHCR and Harbor.
22. How do you decide when a scan fails the build?
Agree on a policy: for example, fail on critical or high findings that have a fixed version available, warn on the rest, and keep a reviewed exception file with expiry dates. Failing on every finding trains teams to ignore the scanner.
23. Should you rebuild the image for each environment?
No. Build once, test that image, then promote the same digest to staging and production. Environment differences go in runtime configuration (environment variables, mounted config, secrets), not into separate builds. Rebuilding means production runs something you never tested.
24. How do you promote an image between registries or repositories?
Copy by digest without rebuilding, for example with docker buildx imagetools create or a registry tool such as crane or skopeo, or add a new tag to the same digest. The digest stays identical, which proves nothing changed.
25. How do you inspect a pushed multi-platform image?
docker buildx imagetools inspect registry.example.com/shop/api:${GIT_SHA} shows the index digest and the per-platform manifests. It is the quickest way to confirm both architectures were pushed.
26. How do you build images in a Kubernetes-based CI system?
Options include a BuildKit deployment used as a remote buildx driver (docker buildx create --driver kubernetes), rootless BuildKit pods, or a privileged DinD sidecar. Avoid mounting the node's container runtime socket into build pods, since that exposes the node.
27. How does GitHub Actions build and push an image?
The common pattern uses docker/setup-buildx-action, docker/login-action, docker/metadata-action for tags and docker/build-push-action to build and push. The GitHub Actions interview questions page covers the workflow side.
28. How do you log in to Amazon ECR from a pipeline?
aws ecr get-login-password --region ap-south-1 \
| docker login --username AWS --password-stdin 123456789012.dkr.ecr.ap-south-1.amazonaws.com
The token is valid for 12 hours, per the ECR registry authentication docs. The CI job should get AWS credentials through an IAM role (OIDC) rather than stored access keys.
29. How do you stop self-hosted runners from filling their disks?
Prune on a schedule (docker builder prune --filter until=72h, docker image prune), cap BuildKit cache size in the builder config, and prefer ephemeral runners that start clean. See Docker image cleanup strategies.
30. How do you keep integration tests isolated when jobs run in parallel on one host?
Give each job its own Compose project name (docker compose -p ci-${JOB_ID}) so networks, volumes and container names do not collide, avoid fixed host ports, and always run down -v in a cleanup step that executes even when tests fail.
31. How do you pin base images in CI?
Pin FROM to a specific version tag or digest, and let a bot such as Dependabot or Renovate open pull requests when a new base digest is published. That gives reproducible builds while still picking up security patches through reviewed changes.
32. What labels should a CI-built image carry?
OCI annotation labels such as org.opencontainers.image.source, org.opencontainers.image.revision and org.opencontainers.image.created. They let anyone inspecting the image find the repository and commit. docker/metadata-action generates them automatically.
Senior Docker CI/CD questions
33. How would you design image tagging for a large organisation?
Every build gets an immutable SHA tag. Release builds also get a semantic version tag. Branch tags like main are moving pointers for humans only. Deployments reference digests, and the registry enforces tag immutability on release repositories (ECR and Harbor support this). Our image tagging best practices post goes deeper.
34. How do you verify in production that an image came from your pipeline?
Sign images or attach provenance in CI (for example with Sigstore cosign, keyless via the CI OIDC identity) and verify the signature at admission time in the cluster with a policy engine such as Kyverno or an equivalent. Unsigned images or images from other builders are rejected.
35. Socket mount, DinD or remote BuildKit: how do you choose?
| Option | Speed | Isolation | Notes |
|---|---|---|---|
| Host socket mount | Fast, shared cache | Weak: job controls host daemon | Only for trusted, single-tenant runners |
| Docker-in-Docker | Medium, cache lost unless persisted | Better, but needs privileged mode | Common in GitLab runners |
| Remote or rootless BuildKit | Fast with shared cache | Good, no privileged job | More setup; cache is shared across tenants |
36. How do you make builds reproducible?
Pin base images by digest, pin package versions with lock files, avoid fetching "latest" artifacts during the build, and set SOURCE_DATE_EPOCH for timestamp reproducibility where the toolchain supports it. Then two builds of the same commit should produce the same layers.
37. What is your rollback strategy for container deployments?
Redeploy the previous known-good digest, which the pipeline recorded at the last release. Because images are immutable and stored in the registry, rollback is a config change, not a rebuild. Keep enough old images in retention rules to cover your rollback window.
38. How do you set registry retention without breaking rollback?
Keep all release-tagged images for a defined period, keep the last N SHA builds per branch, and expire untagged manifests. Never expire images that a running deployment references; some teams export the list of deployed digests to a protected tag.
39. How would you cut a 20-minute Docker build to under five?
Measure first with the build output timings. Then fix ordering so dependencies cache, add registry cache export with mode=max, split independent stages so BuildKit runs them in parallel, use cache mounts for package managers, trim the build context, and move multi-arch builds to native nodes instead of QEMU.
40. How do you handle Docker Hub pull rate limits in CI?
Authenticate pulls with an organisation account, mirror commonly used base images into your own registry or a pull-through cache (ECR, Harbor and Artifact Registry support this), and point Dockerfiles at the mirror. Check the current limits on the Docker Hub usage page, as they have changed over time.
41. How do you keep secrets out of image layers across a whole organisation?
Use build secrets for credentials, add a secret scanner on the repository and on built images, block ARG names that look like tokens through a Dockerfile linter (hadolint) policy, and review docker history output for leaked values during audits.
42. When would you not use Docker in CI?
When the target is not a container (for example a mobile app or a serverless zip package), or when the CI environment cannot run a daemon and a daemonless builder such as Buildah or Kaniko-style tools fits better. Our post on Docker alternatives compares them.
Scenario-based Docker CI/CD questions
43. Builds were fast yesterday and slow today with no Dockerfile change. What do you check?
Check whether the cache import is still working (look for CACHED in the build log), whether the base image digest changed upstream, whether a lock file or early-copied file changed, and whether the runner pool changed to fresh machines without cache.
44. Staging works, production fails with the "same" image. What happened?
Most likely it is not the same image. Compare the digests deployed in both environments. If someone rebuilt for production or a moving tag was re-pushed, the digests differ. Fix the pipeline to promote by digest.
45. A secret appears in docker history of a published image. What now?
Rotate the secret immediately, since removing the image does not un-leak it. Delete the affected tags and digests from the registry, rebuild using a build secret mount, and add a scanner check so it cannot recur.
46. Integration tests fail randomly with "connection refused" to the database.
The tests start before the database is ready. Add a health check to the database service and use depends_on with condition: service_healthy, or start the stack with docker compose up --wait before running tests.
47. The scanner blocks a release for a CVE in a package the app never calls.
Check whether a fixed base image exists and upgrade if so. If not, record a time-limited exception with the justification (for example using a VEX statement or the scanner's ignore file) and get security sign-off. Do not disable the scanner for the whole pipeline.
48. Arm64 nodes in the cluster fail with "exec format error".
The image was built only for amd64. Rebuild with --platform linux/amd64,linux/arm64 and confirm with docker buildx imagetools inspect that both manifests exist.
49. Parallel jobs on one runner break each other's containers.
They share container names, networks or host ports. Use unique Compose project names per job, drop fixed container_name values and published ports where tests can reach services on the Compose network instead.
50. A deploy pulled a different image than CI tested, even though the tag matched.
The tag was overwritten between test and deploy. Enable tag immutability on the repository and pass the digest from the build job to the deploy job as an output.
51. A self-hosted runner reports "no space left on device" weekly.
Build cache and old images accumulate. Add scheduled pruning with age filters, set a BuildKit cache size limit, move Docker's data root to a larger disk if needed, and consider ephemeral runners.
52. Security asks you to remove privileged containers from CI. How do you still build images?
Switch from DinD to a rootless BuildKit service or a remote builder reached over TLS, or use a daemonless builder. Jobs then send build requests without needing privileged mode on the runner.
How to prepare
Build a small app in a public repository with a multi-stage Dockerfile, a Compose file for integration tests and a pipeline that builds, scans, pushes by SHA and records the digest. Be ready to walk an interviewer through that pipeline line by line. If you want guided labs, our Docker training in Pune runs in the Kharadi classroom and live online, and the DevOps training course covers the wider CI/CD toolchain.
FAQs
Is this the same as the Docker scenario-based questions page?
No. The scenario page covers container troubleshooting in general. This page covers Docker inside CI/CD pipelines: caching, tagging, scanning, registries and promotion.
Do I need to know BuildKit for a DevOps interview?
Yes, at least cache export, cache mounts, build secrets and multi-platform builds, because they come up whenever pipeline speed or security is discussed.
Should I deploy by tag or by digest?
By digest. Tags are mutable and can change between test and deploy; a digest always refers to the same content.
Which registry should I learn first?
Learn Docker Hub plus the registry of the cloud you target (ECR, Artifact Registry or ACR) and GHCR if your team uses GitHub. The commands are almost identical.
Is Docker-in-Docker safe for CI?
It needs privileged mode, so it is acceptable on isolated, trusted runners. For shared runners, rootless or remote BuildKit is safer.
How many questions should I prepare for a Docker CI/CD round?
Fewer than you think. Know the 52 here well enough to explain your own pipeline, because interviewers usually drill into one design rather than ask many small questions.
Official references
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0