Docker and CI/CD Middle interview questions and answers
75 questions for a Docker and CI/CD (Middle) interview - with correct answers, explanations and links to the docs.
Take this quiz- 1.What is the main benefit of a multi-stage build?
- 2.Why does this Dockerfile reinstall all dependencies on every code change?
``
dockerfile COPY . . RUN npm ci - 3.Why combine
apt-get updateandapt-get installin oneRUN? - 4.Why does
RUN rm -rf /tmp/buildin a later layer not shrink the image? - 5.What is the difference between
CMD ["node", "server.js"]andCMD node server.js? - 6.Why can a process running as PID 1 in a container misbehave?
- 7.What should a Node.js server do on SIGTERM?
- 8.Why is
CMD ["npm", "start"]discouraged in production images? - 9.After
USER node, the app can't write to/app. What's a common fix? - 10.How do you use an npm token during a build without leaving it in the image?
- 11.What does
RUN --mount=type=cache,target=/root/.npm npm cigive you? - 12.What does BuildKit do with independent stages of a multi-stage build?
- 13.How is an image digest different from a tag?
- 14.What are
<none>:<none>(dangling) images? - 15.What is
compose.override.yamlused for? - 16.What are Compose profiles for?
- 17.You bind-mount the project into a Node container and the app can't find its modules. Why?
- 18.In Compose, what is the difference between the
.envfile andenv_file:? - 19.A container stops with exit code 137. What is the likely cause?
- 20.Why may Node.js ignore a container's memory limit and get OOM-killed?
- 21.What does
--network hostdo? - 22.Why should containers log to stdout and stderr?
- 23.What prevents Docker's default
json-filelogs from filling the disk? - 24.What does running with
--read-onlyachieve? - 25.What is a distroless image?
- 26.Why install only production dependencies in the final image?
- 27.What does an image scanner such as Trivy check?
- 28.Why is mounting
/var/run/docker.sockinto a container risky? - 29.An image built on an Apple Silicon Mac fails on an x86 server with
exec format error. Why? - 30.What does
exec "$@"do at the end of an entrypoint script? - 31.Does Kubernetes use the Dockerfile
HEALTHCHECK? - 32.What makes a good cache key for
node_modulesor the npm cache in CI? - 33.Cache vs artifacts in CI: what's the difference?
- 34.What does this do?
``
yaml concurrency: group: deploy-${{ github.ref }} cancel-in-progress: true - 35.In a monorepo, how can you avoid running the backend pipeline when only the frontend changed?
- 36.What is
workflow_dispatchfor? - 37.Why set
permissions:explicitly forGITHUB_TOKEN? - 38.Why don't workflows triggered by
pull_requestfrom forks get repository secrets? - 39.What do deployment environments with required reviewers add?
- 40.What is a reusable workflow?
- 41.What is a composite action?
- 42.Why pin third-party actions to a full commit SHA rather than
@v3? - 43.What does OIDC give a CI pipeline that deploys to a cloud provider?
- 44.How does one job pass a value, such as an image tag, to another?
- 45.How do you run a deploy step only for pushes to
main? - 46.What does
fail-fast: falsechange in a matrix? - 47.Why are self-hosted runners risky for public repositories?
- 48.Why are Docker builds on fresh CI runners often slow, and what helps?
- 49.Why tag images with the commit SHA?
- 50.How do you speed up a slow pipeline without dropping checks?
- 51.How can integration tests in GitHub Actions get a real PostgreSQL?
- 52.What does Testcontainers do?
- 53.Why should database migrations stay backward compatible during a deploy?
- 54.What is a canary release?
- 55.What does a rolling update do?
- 56.How do feature flags change the relationship between deploy and release?
- 57.What are smoke tests after a deploy for?
- 58.Which are the classic DORA metrics?
- 59.What does "lead time for changes" measure?
- 60.Why do CI and long-lived feature branches work against each other?
- 61.What is infrastructure as code?
- 62.What is the core idea of GitOps?
- 63.Readiness vs liveness probe in Kubernetes: what's the difference?
- 64.Why do you usually create a Deployment rather than Pods directly?
- 65.Are Kubernetes Secrets encrypted by default?
- 66.Resource requests vs limits in Kubernetes: what do they do?
- 67.What do
maxSurgeandmaxUnavailablecontrol? - 68.What do Dependabot or Renovate do?
- 69.Why shouldn't you overwrite an existing image tag like
1.4.0? - 70.What does
needs:change in a GitLab CI job? - 71.CI masks secret values in logs. Why can a secret still leak?
- 72.Why should every production deploy go through the pipeline, not a manual
docker pushfrom a laptop? - 73.What does
docker history my-apphelp you find? - 74.What does
docker compose configprint? - 75.What does
restore-keysadd to a cache step?