Scenario Questions
Real-world Docker situations and how to reason through them in an interview
Image design and Dockerfile decisions
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q1 A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?
Beginner
Situation read โ Large image usually means a fat base, dev dependencies, build tools and a copied build context.
What I'd do โ
- Run
docker history --no-trunc myapp:latestanddocker image lsto see which layers are big. - Switch from
node:22tonode:22-slimornode:22-alpine(test musl compatibility first). - Use
npm ci --omit=devand add a.dockerignorewithnode_modules,.git,*.md. - Move to multi-stage so build tooling never ships.
Why โ Every layer is additive; deleting files in a later layer does not shrink the image.
Interview tip โ Say you measure with docker history or dive before optimizing.
Q2 You need to run apt-get install in a Dockerfile. How do you write it so the layer stays small and cache-safe?
Beginner
apt-get install in a Dockerfile. How do you write it so the layer stays small and cache-safe?Situation read โ Classic layer hygiene question.
What I'd do โ
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates \
&& rm -rf /var/lib/apt/lists/*- Chain
updateandinstallin oneRUNso a stale package index is never cached alone. - Use
--no-install-recommends. - Remove
/var/lib/apt/listsin the same layer. - Pin versions for critical packages if reproducibility matters.
Why โ Cleanup in a separate RUN leaves the data in the earlier layer.
Interview tip โ Mention BuildKit cache mounts as the modern alternative: RUN --mount=type=cache,target=/var/cache/apt.
Q3 When would you pick COPY over ADD?
Beginner
COPY over ADD?Situation read โ Both copy files; ADD has extra behaviours.
What I'd do โ Default to COPY. Use ADD only for auto-extracting a local tar (ADD app.tar.gz /opt/) or for ADD --checksum=sha256:... https://... /file and git URLs.
Why โ ADD with remote URLs and silent extraction is surprising and hard to cache or audit. For downloads I prefer curl plus checksum verification in a RUN, or ADD --checksum.
Interview tip โ "COPY for intent clarity, ADD for the two cases COPY cannot do."
Q4 A service must run a startup script and then the app. Should you use CMD, ENTRYPOINT, or both?
Beginner
CMD, ENTRYPOINT, or both?Situation read โ Entrypoint scripts are common for config templating or migrations.
What I'd do โ
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node", "server.js"]End the script with exec "$@" so the app replaces the shell and becomes PID 1.
Why โ ENTRYPOINT is the fixed executable, CMD is the default, overridable argument list. Without exec, SIGTERM goes to the shell and the app is killed after the 10 s timeout.
Interview tip โ Always use exec form (JSON array), never shell form, for the main process.
Q5 Your Docker build re-installs all Python dependencies on every code change. Fix it.
Beginner
Situation read โ COPY . . comes before pip install, so any file change busts the cache.
What I'd do โ
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .Add a .dockerignore so irrelevant changes (.git, __pycache__) do not invalidate COPY . . either.
Why โ Layers are cached top-down; order from least to most frequently changing.
Interview tip โ State the rule: "dependencies manifest first, source last."
Q6 Product asks for a container that runs both nginx and a Python app. What do you say?
Beginner
Situation read โ One-process-per-container is a guideline, not a law, but mixing hurts signal handling, scaling and logs.
What I'd do โ
- Propose two containers (nginx + app) in one Compose file or one Pod.
- Share traffic via a user-defined network, or a Unix socket on a shared volume.
- If truly required, use a minimal init such as
tiniors6-overlayto supervise both.
Why โ Independent restarts, independent scaling, clean docker logs per concern.
Interview tip โ Acknowledge the exception (sidecars/supervised legacy apps) rather than being dogmatic.
Q7 Your app ignores docker stop and takes exactly 10 seconds to die. Why and what do you change?
Intermediate
docker stop and takes exactly 10 seconds to die. Why and what do you change?Situation read โ The process is not receiving or handling SIGTERM, so Docker sends SIGKILL after the grace period.
What I'd do โ
- Check
docker inspect -f '{{.Config.Entrypoint}} {{.Config.Cmd}}' cfor shell form (/bin/sh -c ...). - Switch to exec form or add
execin the wrapper script. - If the app does not reap zombies or handle signals, run with
--init(tini). - Handle SIGTERM in the app (graceful shutdown) and optionally set
STOPSIGNALand--stop-timeout.
Why โ PID 1 in a container gets no default signal handlers from the kernel; it must install its own.
Interview tip โ Mention docker run --init as the zero-code fix.
Q8 You must pass a database password into an image at build time to download a private package. How?
Intermediate
Situation read โ ARG/ENV values persist in image history; never use them for secrets.
What I'd do โ Use BuildKit secrets:
# syntax=docker/dockerfile:1
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm cidocker build --secret id=npmrc,src=$HOME/.npmrc .Why โ The secret is mounted in tmpfs for that RUN only and never lands in a layer or docker history.
Interview tip โ Also mention --mount=type=ssh for private git clones.
Q9 A developer wants latest base images always. Your view?
Beginner
latest base images always. Your view?Situation read โ latest is a moving target; builds become non-reproducible.
What I'd do โ Pin to a specific minor version (python:3.12-slim-bookworm) and ideally to a digest: FROM python:3.12-slim-bookworm@sha256:.... Let Renovate or Dependabot open PRs to bump tags and digests.
Why โ You get reproducible builds and reviewable upgrades, and security patches still flow through automated PRs.
Interview tip โ Tag for readability, digest for immutability; use both together.
Q10 You need a tiny static Go binary in production. Which base image do you choose?
Intermediate
Situation read โ Static binaries do not need a libc or a package manager.
What I'd do โ
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o /out/app ./cmd/app
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]scratch works too but lacks CA certificates and /etc/passwd; distroless static includes both.
Why โ Minimal attack surface, a few MB image.
Interview tip โ Mention you lose a shell; use docker debug or an ephemeral debug container.
Q11 Alpine or Debian slim for a Python app with compiled wheels?
Intermediate
Situation read โ Alpine uses musl libc; many PyPI wheels are built for glibc (manylinux).
What I'd do โ Choose python:3.12-slim (Debian) for packages like numpy, pandas, grpcio, cryptography. Pick Alpine only if all dependencies have musllinux wheels or you accept compiling from source.
Why โ On Alpine, pip often compiles from source, which makes builds slow and images larger after installing a toolchain, and can produce subtle runtime differences (DNS resolver, locale, performance).
Interview tip โ "Smaller base is not always smaller final image."
Q12 How do you make an image reproducible so the same commit gives the same bytes?
Advanced
Situation read โ Timestamps, unpinned packages and unordered layers cause drift.
What I'd do โ
- Pin base by digest and OS packages by version or use a snapshot mirror (e.g. snapshot.debian.org).
- Use lockfiles (
npm ci,pip --require-hashes,go.sum). - Build with
SOURCE_DATE_EPOCHand--output type=image,rewrite-timestamp=trueon BuildKit. - Use
-trimpathand deterministic compilers settings.
Why โ Reproducibility allows independent verification of provenance and attestations.
Interview tip โ Be honest that full bit-for-bit reproducibility is hard; aim for it on the supply-chain-critical images.
Q13 A Dockerfile has RUN cd /app followed by RUN npm install and it fails. Why?
Beginner
RUN cd /app followed by RUN npm install and it fails. Why?Situation read โ Each RUN starts a fresh shell; cd does not persist across instructions.
What I'd do โ Use WORKDIR /app (which also creates the directory) and then RUN npm install. Or chain: RUN cd /app && npm install.
Why โ Only filesystem changes persist between layers, not shell state such as cwd or exported variables.
Interview tip โ Same reason RUN export FOO=bar is useless; use ENV.
Q14 Your team needs different config per environment. Bake it in the image or inject it?
Beginner
Situation read โ Build once, deploy many.
What I'd do โ Keep one image for all environments and inject config at runtime via -e, --env-file, mounted config files, Compose configs, or Kubernetes ConfigMaps/Secrets. Only non-secret defaults go in ENV.
Why โ Rebuilding per environment means what you tested is not what you deploy, and secrets could leak into layers.
Interview tip โ Twelve-factor: config in the environment.
Q15 You want to know exactly what commands produced an image you did not build.
Beginner
Situation read โ Image metadata keeps a build history.
What I'd do โ
docker history --no-trunc --format '{{.CreatedBy}}' nginx:1.27
docker inspect nginx:1.27 | jq '.[0].Config'For deeper layer content use dive nginx:1.27 or docker save and untar. For BuildKit images also docker buildx imagetools inspect --format '{{json .Provenance}}' image.
Why โ History shows instructions; attestations give signed provenance when published.
Interview tip โ History can be forged or squashed, so for trust use signatures and provenance.
Q16 How do you handle timezone and locale in minimal images?
Beginner
Situation read โ Slim images ship without tzdata, so TZ=Asia/Kolkata is silently ignored.
What I'd do โ
RUN apt-get update && apt-get install -y --no-install-recommends tzdata \
&& rm -rf /var/lib/apt/lists/*
ENV TZ=Asia/KolkataBetter practice: keep containers on UTC and format time in the UI layer.
Why โ Logs and cron across services stay comparable.
Interview tip โ Mention Go's time/tzdata import to embed zone data in a static binary.
Q17 A PR adds COPY . . and a developer's .env file ends up in the image. How do you prevent and remediate?
Intermediate
COPY . . and a developer's .env file ends up in the image. How do you prevent and remediate?Situation read โ Secrets in a layer are recoverable by anyone with the image.
What I'd do โ
- Add
.env,.git,*.pem,id_rsa*to.dockerignore(allow-list style: ignore*, then!src). - Rotate every secret in that file immediately.
- Delete the pushed tags and rebuild; deleting a later layer is not enough.
- Add a CI scan (trivy
--scanners secret, gitleaks).
Why โ docker save exposes all layers.
Interview tip โ Remediation order: rotate first, clean up second.
Q18 Should you run chmod/chown in a separate RUN after COPY?
Intermediate
chmod/chown in a separate RUN after COPY?Situation read โ A separate RUN chown -R duplicates all copied files into a new layer, doubling size.
What I'd do โ
COPY --chown=app:app --chmod=0755 entrypoint.sh /usr/local/bin/
COPY --chown=app:app . /appWhy โ The metadata is set at copy time, with no duplicated layer.
Interview tip โ --chmod requires BuildKit; it is the default builder since Docker 23.
Q19 How do you run a container as a non-root user in a Dockerfile properly?
Beginner
Situation read โ Default is root; compromise of the app gives root inside the container.
What I'd do โ
RUN groupadd -r app --gid=10001 && useradd -r -g app --uid=10001 app
WORKDIR /app
COPY --chown=app:app . .
USER 10001:10001Use a numeric UID so Kubernetes runAsNonRoot can verify it.
Why โ Limits blast radius and works with read-only root filesystems.
Interview tip โ Ports below 1024 need CAP_NET_BIND_SERVICE or sysctl; use 8080 instead.
Q20 What is the difference between ARG and ENV, and when does each matter?
Beginner
ARG and ENV, and when does each matter?Situation read โ One is build-time, the other persists into the running container.
What I'd do โ Use ARG for build parameters (ARG APP_VERSION) and ENV for runtime variables. An ARG declared before FROM is only usable in FROM lines unless redeclared after it. Convert when needed: ENV VERSION=$APP_VERSION.
Why โ ARG values appear in docker history and do not exist at runtime; ENV values are visible to anyone with docker inspect.
Interview tip โ Neither is a safe place for secrets.
Q21 You must support both amd64 and arm64 users (Apple Silicon laptops, Graviton in prod).
Intermediate
Situation read โ Need a multi-arch manifest list.
What I'd do โ
docker buildx create --use --name multi
docker buildx build --platform linux/amd64,linux/arm64 \
-t registry.example.com/app:1.4.0 --push .In the Dockerfile use ARG TARGETARCH for arch-specific downloads and cross-compile in the build stage with FROM --platform=$BUILDPLATFORM to avoid slow QEMU emulation.
Why โ One tag resolves to the right image per node.
Interview tip โ Verify with docker buildx imagetools inspect app:1.4.0.
Q22 When is docker commit acceptable?
Beginner
docker commit acceptable?Situation read โ It snapshots a container's filesystem into an image.
What I'd do โ Only for quick debugging or forensics (preserve a compromised container's state). Never for shipping: the result is not reproducible, has no recorded steps and can include secrets and caches.
Why โ A Dockerfile in git is reviewable and rebuildable; a committed image is a black box.
Interview tip โ docker diff <container> shows what changed, useful for turning manual fixes into Dockerfile lines.
Q23 Which HEALTHCHECK command do you use in a distroless image with no curl?
Intermediate
HEALTHCHECK command do you use in a distroless image with no curl?Situation read โ No shell and no curl means a Dockerfile HEALTHCHECK CMD curl fails.
What I'd do โ Add a tiny health subcommand to the app binary (/app healthcheck) and use exec form:
HEALTHCHECK --interval=15s --timeout=3s --start-period=20s --retries=3 \
CMD ["/app", "healthcheck"]Alternatively rely on orchestrator probes (Kubernetes HTTP probes) instead of Docker's.
Why โ Keeps the image minimal while retaining health semantics.
Interview tip โ In Kubernetes, the Dockerfile HEALTHCHECK is ignored; use probes.
Q24 A build needs a 2 GB dataset only for tests. How do you keep it out of the image?
Intermediate
Situation read โ Anything COPYed in any stage of the final image's chain stays in it.
What I'd do โ
- Put tests in a separate stage (
FROM build AS test) and run withdocker build --target test. - Mount the data with
RUN --mount=type=bind,source=testdata,target=/testdata .... - Exclude it in
.dockerignorefrom the default context.
Why โ Bind and cache mounts exist only during the RUN step and are not committed.
Interview tip โ Use --target to produce different artifacts from one Dockerfile.
Q25 How do you decide between a Dockerfile VOLUME instruction and not declaring it?
Advanced
VOLUME instruction and not declaring it?Situation read โ VOLUME /data forces an anonymous volume at run time and freezes later changes to that path in the build.
What I'd do โ Avoid VOLUME in my own images; document paths and let operators mount named volumes or bind mounts. Use it only for images where data persistence by default is a safety feature (e.g. databases like the official postgres image).
Why โ Any RUN chown /data after VOLUME /data is silently discarded, and anonymous volumes pile up (docker volume ls -f dangling=true).
Interview tip โ Mention docker run --rm removes anonymous volumes with the container; -v flag on docker rm -v does too.
Multi-stage builds, cache, tags and registries
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q26 Show a multi-stage Dockerfile for a Java Spring Boot app and explain what you gain.
Beginner
Situation read โ JDK and Maven are needed to build, only a JRE is needed to run.
What I'd do โ
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /src
COPY pom.xml .
RUN --mount=type=cache,target=/root/.m2 mvn -q dependency:go-offline
COPY src ./src
RUN --mount=type=cache,target=/root/.m2 mvn -q package -DskipTests
FROM eclipse-temurin:21-jre
COPY --from=build /src/target/app.jar /app.jar
USER 10001
ENTRYPOINT ["java","-jar","/app.jar"]Why โ Final image carries only the JRE and jar, usually 250 MB instead of 700 MB+.
Interview tip โ Mention the Maven cache mount for fast rebuilds.
Q27 CI rebuilds from scratch every run and takes 12 minutes. How do you bring it down?
Intermediate
Situation read โ Ephemeral CI runners have no local layer cache.
What I'd do โ
- Use BuildKit remote cache:
docker buildx build \
--cache-from type=registry,ref=reg.example.com/app:buildcache \
--cache-to type=registry,ref=reg.example.com/app:buildcache,mode=max \
-t reg.example.com/app:$SHA --push .- On GitHub Actions use
type=gha. - Reorder the Dockerfile so deps are above source.
Why โ mode=max also exports intermediate stages, so multi-stage builds get cache hits.
Interview tip โ Say you track cache hit rate from the CACHED lines in build output.
Q28 You tag every build myapp:latest. A rollback is requested. What happens?
Beginner
myapp:latest. A rollback is requested. What happens?Situation read โ latest was overwritten; the previous image is untagged ("dangling") or only in registry history.
What I'd do โ Going forward tag with the git SHA and semantic version (app:1.8.2, app:git-3f2c1a9), deploy by digest, and keep latest only as a convenience. For the immediate rollback find the old digest in registry logs, a deploy manifest, or a node's docker image ls --digests.
Why โ Immutable references make rollback a config change, not a rebuild.
Interview tip โ Tags are mutable pointers; digests are content addresses.
Q29 How do you promote an image from dev to prod registry without rebuilding?
Intermediate
Situation read โ Same bytes must go to prod.
What I'd do โ
docker buildx imagetools create \
-t prod.example.com/app:1.8.2 dev.example.com/app@sha256:ab12...
# or
skopeo copy --all docker://dev.example.com/app@sha256:ab12... \
docker://prod.example.com/app:1.8.2
# or
crane copy dev.example.com/app@sha256:ab12... prod.example.com/app:1.8.2Why โ Digest equality proves what was tested is what runs; --all preserves multi-arch manifests.
Interview tip โ docker pull/tag/push works but pulls only your platform.
Q30 Disk on the build server keeps filling up with images.
Beginner
Situation read โ Old tags, dangling layers and build cache accumulate.
What I'd do โ
docker system df
docker image prune -a --filter "until=168h"
docker builder prune --filter "until=72h" --keep-storage 20GBRun it from a nightly cron or a CI cleanup job and configure BuildKit GC in buildkitd.toml.
Why โ docker system prune -a is blunt and can delete images other jobs need.
Interview tip โ Do not prune volumes unattended; that deletes data.
Q31 When do you use --no-cache and when is it a smell?
Beginner
--no-cache and when is it a smell?Situation read โ It forces every layer to be rebuilt.
What I'd do โ Use it occasionally (weekly scheduled build) to pull in OS security updates when you do not pin packages, or when debugging cache poisoning. As a default in CI it is a smell: it hides poor layer ordering and slows everything.
Why โ Better: bump a build ARG such as CACHE_BUST at a chosen layer, or use --pull to refresh the base.
Interview tip โ --pull and --no-cache solve different problems.
Q32 Explain a build where COPY always misses the cache even though code did not change.
Intermediate
COPY always misses the cache even though code did not change.Situation read โ Cache key for COPY is a checksum of file contents and metadata (mode), not mtime.
What I'd do โ
- Look for generated files in context (
build/,*.log,.DS_Store, version stamp files) and add them to.dockerignore. - Check that a script rewrites file permissions on checkout.
- Run
docker buildx build --progress=plain .and compare which step is notCACHED.
Why โ One changed byte in the copied set invalidates this layer and all after it.
Interview tip โ Copy narrowly (COPY src/ src/) rather than the whole context.
Q33 Design a tagging strategy for a team that releases weekly.
Intermediate
Situation read โ Need traceability, rollback and human friendliness.
What I'd do โ
- Every CI build:
app:<git-sha>(immutable, never re-pushed). - Releases:
app:1.8.2, plus floating1.8and1. - Environments reference digests via GitOps (
image: app@sha256:...) with the tag in a comment. latestonly for dev.- Registry tag immutability enabled (ECR, Harbor).
Why โ Floating tags help consumers, immutable tags help operators.
Interview tip โ Mention retention policies so old SHA tags age out.
Q34 How do you target a single stage while debugging a multi-stage build?
Beginner
Situation read โ Need to inspect the build stage output.
What I'd do โ
docker build --target build -t app:debug .
docker run --rm -it app:debug shUse docker buildx build --target test --progress=plain . to run only tests.
Why โ BuildKit only builds stages the target depends on, which also saves time.
Interview tip โ Name stages with AS for readability.
Q35 The registry has 40,000 images and storage costs are rising.
Intermediate
Situation read โ No retention policy, SHA tags per commit.
What I'd do โ
- Define policy: keep last N tags per branch, keep all release tags, expire untagged after 14 days (ECR lifecycle policy, Harbor retention, GCR cleanup policies).
- Run garbage collection (
registry garbage-collectfor self-hosted). - Dedupe by promoting only release candidates to long-lived repos.
Why โ Layers are shared, so deletes only free blobs no manifest references.
Interview tip โ Test policies in dry-run mode first.
Q36 You want to verify that the image a node pulled is the one CI built and signed.
Advanced
Situation read โ Tag-only trust can be hijacked by a registry compromise or accidental overwrite.
What I'd do โ
- Sign in CI:
cosign sign --yes reg.example.com/app@sha256:...(keyless via OIDC). - Attach SBOM and provenance:
docker buildx build --sbom=true --provenance=mode=max. - Enforce at admission: Kyverno or Sigstore policy-controller verifying the signature identity and issuer.
- Locally verify:
cosign verify --certificate-identity-regexp ... --certificate-oidc-issuer https://token.actions.githubusercontent.com image@sha256:....
Why โ Verifies who built it and that the content has not changed.
Interview tip โ Sign digests, not tags.
Q37 Pull rate limits from Docker Hub are failing CI. What are your options?
Intermediate
Situation read โ Anonymous pulls are rate limited per IP; shared NAT in CI exhausts it.
What I'd do โ
- Authenticate pulls with a Docker Hub service account (
docker login). - Set up a pull-through cache (Harbor proxy project, ECR pull-through cache,
registry:2withproxy.remoteurl). - Mirror critical base images into our own registry and reference those.
- Configure
registry-mirrorsindaemon.json.
Why โ Reduces external dependency and speeds up pulls.
Interview tip โ Mirroring base images also protects you from upstream tag removal.
Q38 What does it mean that docker push says "Layer already exists"?
Beginner
docker push says "Layer already exists"?Situation read โ Registries store blobs by content digest.
What I'd do โ Nothing; it is a feature. The registry already has that layer (from a prior push or another repo with cross-repo mount), so the client skips upload. Only the manifest and changed layers transfer.
Why โ This is why stable base layers and good ordering make pushes and pulls fast.
Interview tip โ Same logic speeds pulls: nodes only fetch missing layers.
Q39 How do you inspect a remote image's size, platforms and digest without pulling it?
Beginner
Situation read โ Need metadata only.
What I'd do โ
docker buildx imagetools inspect nginx:1.27
docker manifest inspect nginx:1.27
crane manifest nginx:1.27 | jq
skopeo inspect docker://nginx:1.27
crane digest nginx:1.27Why โ These talk to the registry API and fetch manifests, not layers.
Interview tip โ imagetools inspect shows the manifest list with per-platform digests.
Q40 A multi-stage build copies from --from=build but the final image is still huge. Why?
Intermediate
--from=build but the final image is still huge. Why?Situation read โ Probably copying a whole directory (COPY --from=build /src /app) including node_modules dev deps or source, or the final stage is built FROM build.
What I'd do โ
docker history appto find the heavy layer.- Copy only artifacts (
/src/dist, the binary). - Install prod-only deps in the final stage or prune (
npm prune --omit=dev). - Verify with
dive.
Why โ Multi-stage only helps if the last stage starts from a clean base.
Interview tip โ Check that the last FROM is the slim runtime image.
Q41 How do you share a common base layer across 30 microservices?
Intermediate
Situation read โ Repeating the same hardening steps in every Dockerfile wastes build time and drifts.
What I'd do โ Build an internal golden base (registry/base/python:3.12-2026w45) with CA bundles, non-root user, tzdata and agent config. Rebuild weekly, scan, sign and publish. Services FROM it by digest; Renovate bumps the digest.
Why โ One place to patch, shared layers on nodes, consistent security posture.
Interview tip โ Keep the base thin; a fat shared base becomes a dependency trap.
Q42 What is a dangling image and is it safe to delete?
Beginner
Situation read โ An image with no tag, shown as <none>:<none>, usually left when a tag moved to a new build.
What I'd do โ
docker images -f dangling=true
docker image pruneWhy โ Safe unless a running container or another image depends on it, in which case Docker refuses or keeps it as a parent layer. -a removes all unused images, not only dangling ones.
Interview tip โ Distinguish dangling (untagged) from unused (no container).
Q43 Cache mounts in Dockerfiles: when are they worth it?
Intermediate
Situation read โ Package managers redownload packages on each change of the dependency layer.
What I'd do โ
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go build ./...Why โ The cache directory persists between builds on the same builder but never enters the image, so you get speed without size. It is not shared across CI runners unless the builder is persistent.
Interview tip โ On ephemeral CI combine with registry cache or a long-lived buildkit daemon.
Q44 Your pull from a private registry works locally but fails on the Kubernetes node with containerd.
Intermediate
Situation read โ Docker credentials in ~/.docker/config.json are not used by containerd or kubelet.
What I'd do โ Create an imagePullSecret (kubectl create secret docker-registry regcred ...) and reference it in the Pod or ServiceAccount, or configure kubelet image credential providers (ECR, GCR, ACR). Check with crictl pull on the node.
Why โ Each runtime has its own auth path.
Interview tip โ Cloud credential providers avoid long-lived static passwords.
Q45 How would you rollback a bad image deployed via Docker Compose on one host?
Beginner
Situation read โ Compose has no built-in rollback.
What I'd do โ
- Edit the
image:to the previous known-good tag or digest. docker compose pull && docker compose up -d --no-deps web.- Confirm with
docker compose psanddocker compose logs -f web.
Why โ Works only because old tags are retained, which is why we never overwrite tags.
Interview tip โ For zero downtime and automatic rollback move to Swarm or Kubernetes.
Q46 What is the difference between docker save/load and export/import?
Intermediate
docker save/load and export/import?Situation read โ Moving images into an air-gapped network.
What I'd do โ docker save -o app.tar app:1.8.2 then docker load -i app.tar on the target: preserves layers, tags and history. docker export dumps a container's flattened filesystem and docker import makes a single-layer image, losing metadata like ENTRYPOINT and ENV.
Why โ Use save/load for images; export/import is for filesystem snapshots.
Interview tip โ For air-gap, skopeo copy docker://... oci-archive: is cleaner and can verify digests.
Q47 You need to run integration tests against the exact image you will ship.
Intermediate
Situation read โ Testing a different build than the one released defeats the purpose.
What I'd do โ
- Build once and load:
docker buildx build --load -t app:$SHA .. - Start dependencies with Compose, run tests against
app:$SHA(Testcontainers ordocker compose up --wait). - Push that same digest only if tests pass.
Why โ Promote the artefact, not the source.
Interview tip โ docker compose up --wait blocks until health checks pass.
Q48 Developers complain builds are slow on Apple Silicon for amd64 targets.
Advanced
Situation read โ QEMU emulation of amd64 is 5โ20x slower.
What I'd do โ
- Cross-compile natively:
FROM --platform=$BUILDPLATFORM golang AS buildand setGOOS=$TARGETOS GOARCH=$TARGETARCH. - Use remote native builders:
docker buildx create --name farm --node amd64 --platform linux/amd64 ssh://builderplus a local arm64 node. - Enable Rosetta in Docker Desktop for amd64 emulation where needed.
- Build multi-arch in CI on native runners and merge manifests.
Why โ Native or cross-compile beats emulation.
Interview tip โ Languages without easy cross-compilers need native nodes.
Q49 How do you keep a latest tag but still know which build it points to?
Beginner
latest tag but still know which build it points to?Situation read โ Operators need traceability.
What I'd do โ Add OCI labels at build time:
LABEL org.opencontainers.image.revision=$GIT_SHA \
org.opencontainers.image.source=https://github.com/acme/app \
org.opencontainers.image.created=$BUILD_DATEThen docker inspect -f '{{json .Config.Labels}}' app:latest. Or use docker/metadata-action to generate them.
Why โ Labels travel with the image.
Interview tip โ The org.opencontainers.image.* namespace is the standard.
Q50 What are the risks of using a public image straight from Docker Hub in production?
Intermediate
Situation read โ Supply-chain exposure.
What I'd do โ
- Prefer Docker Official Images, Verified Publisher or Docker Hardened Images.
- Mirror into our registry, scan and sign before use.
- Pin by digest.
- Review the Dockerfile, check maintenance cadence and CVE counts.
Why โ Tags can be repointed, images can be abandoned, and typo-squatted images carry malware.
Interview tip โ Treat third-party images as third-party code.
Volumes, storage and data
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q51 A Postgres container was removed and the data is gone. How should it have been run?
Beginner
Situation read โ Data lived in the container's writable layer (or an anonymous volume that was removed with --rm/-v).
What I'd do โ
docker volume create pgdata
docker run -d --name pg -v pgdata:/var/lib/postgresql/data \
-e POSTGRES_PASSWORD_FILE=/run/secrets/pg -p 127.0.0.1:5432:5432 postgres:17Back up with pg_dump on a schedule; do not treat the volume as a backup.
Why โ Named volumes outlive containers and are managed by Docker.
Interview tip โ Note that for the postgres image the mount path changed to /var/lib/postgresql for v18+; check the image docs.
Q52 Bind mount or named volume for local development of a Node app?
Beginner
Situation read โ Developers want live code reload.
What I'd do โ Bind mount the source (-v $PWD:/app) and shadow node_modules with a named or anonymous volume (-v /app/node_modules) so host and container binaries do not clash. With Compose use develop.watch (action: sync) for efficient syncing.
Why โ Bind mounts reflect host edits instantly; volumes are better for data and performance on macOS/Windows.
Interview tip โ Bind mounts in prod couple the container to host paths; avoid them there.
Q53 How do you back up a named volume?
Intermediate
Situation read โ Volume data lives under /var/lib/docker/volumes, but you should not poke at it directly.
What I'd do โ
docker run --rm -v pgdata:/data:ro -v $PWD:/backup alpine \
tar czf /backup/pgdata-$(date +%F).tgz -C /data .For databases prefer logical dumps or snapshot after CHECKPOINT/with the DB quiesced, because a file copy of a running DB can be inconsistent.
Why โ A helper container uses the Docker API and respects drivers.
Interview tip โ Test restores, not just backups.
Q54 Two containers must share files. What are your options?
Beginner
Situation read โ Typical for a web server serving files generated by an app.
What I'd do โ
- A shared named volume mounted in both (
-v assets:/srv/assets, read-only in the consumer). --volumes-from producerfor a quick link.- For cross-host, NFS volume driver or object storage instead.
Why โ Volumes avoid host path dependency; use :ro where possible.
Interview tip โ Concurrent writers need app-level locking; Docker does not provide it.
Q55 A container needs a writable temp area but the root filesystem is read-only.
Intermediate
Situation read โ --read-only is a hardening best practice but apps still write to /tmp and /run.
What I'd do โ
docker run --read-only --tmpfs /tmp:rw,noexec,nosuid,size=64m \
--tmpfs /run -v appdata:/var/lib/app myappWhy โ Writes land only in explicitly allowed places, and tmpfs is in memory so it vanishes on stop.
Interview tip โ tmpfs counts against the container memory limit.
Q56 Moving a database volume from one Docker host to another.
Intermediate
Situation read โ Need consistent data transfer with minimal downtime.
What I'd do โ
- Prefer a logical migration:
pg_dump | psqlor replication. - If you must copy files, stop the container first, then:
docker run --rm -v pgdata:/from alpine tar c -C /from . | \
ssh new-host 'docker run --rm -i -v pgdata:/to alpine tar x -C /to'- Start with the same image major version.
Why โ Copying files from a running DB risks corruption.
Interview tip โ Same major version is mandatory for binary data directories.
Q57 Explain how copy-on-write affects performance of a write-heavy container.
Advanced
Situation read โ Writes to files from lower image layers trigger a copy-up to the writable layer; writes to the container layer go through overlayfs.
What I'd do โ Put write-heavy paths (DB data, logs, queues, build caches) on volumes, which bypass the storage driver and give near-native I/O. Check driver with docker info | grep -i storage (expect overlay2 or the containerd snapshotter overlayfs).
Why โ Copy-up of a large file (e.g., a 1 GB file touched by 1 byte) is expensive and repeated across containers.
Interview tip โ "Data on volumes, code in layers."
Q58 How would you limit how much disk a container can write?
Advanced
Situation read โ One runaway container fills the host disk.
What I'd do โ
docker run --storage-opt size=10Gworks on overlay2 only with an XFS backing filesystem mounted withpquota.- Alternatively put
/var/lib/dockeron its own filesystem or LV so it cannot starve the root disk. - Use
--tmpfs size=for scratch space and log rotation for logs. - In Kubernetes use
ephemeral-storagelimits.
Why โ Docker has no portable per-container disk quota on ext4.
Interview tip โ Monitor docker system df -v and node disk pressure.
Q59 A volume driver for NFS is required for a Swarm service.
Advanced
Situation read โ Tasks can land on any node, so data must be reachable everywhere.
What I'd do โ Use the built-in local driver with NFS options:
docker volume create --driver local \
--opt type=nfs --opt o=addr=10.0.0.5,rw,nfsvers=4 \
--opt device=:/exports/app shared-dataIn a stack file define the volume with driver_opts.
Why โ The mount happens on whichever node runs the task.
Interview tip โ Mention that NFS adds latency and a single point of failure; databases should not live there without care.
Q60 You need to find which container is using a volume before deleting it.
Beginner
Situation read โ docker volume rm fails with "volume is in use".
What I'd do โ
docker ps -a --filter volume=pgdata --format '{{.ID}} {{.Names}} {{.Status}}'
docker volume inspect pgdataStop and remove the referencing containers, then docker volume rm pgdata.
Why โ Stopped containers still hold references.
Interview tip โ docker volume prune removes unused volumes (anonymous only unless -a); never run it blindly in prod.
Q61 Application writes files as UID 1000 but the mounted host directory is root-owned.
Intermediate
Situation read โ Permission denied on bind mount caused by UID mismatch.
What I'd do โ
chown 1000:1000 /srv/app-dataon the host, or run with--user $(id -u):$(id -g).- With named volumes, Docker copies ownership from the image path on first use, so
chownin the Dockerfile before first mount. - On SELinux hosts add
:zor:Z.
Why โ The kernel checks numeric IDs, not names.
Interview tip โ With rootless/userns-remap the host UID differs from the container UID.
Q62 Should log files go to a volume?
Beginner
Situation read โ Apps writing to /var/log/app.log inside the container.
What I'd do โ Log to stdout/stderr so Docker's logging driver collects them. For legacy apps symlink /var/log/app.log to /dev/stdout as the nginx image does.
Why โ Works with docker logs, centralized shippers and rotation, with no volume to clean.
Interview tip โ Twelve-factor: treat logs as event streams.
Q63 A legacy app needs persistent state, but the team wants to scale it to 3 replicas.
Advanced
Situation read โ Shared local state blocks horizontal scaling.
What I'd do โ
- Identify what state it holds (sessions, uploads, cache).
- Move sessions to Redis, uploads to S3-compatible storage, DB state to a managed database.
- If state must stay on disk, use per-replica volumes (StatefulSet in Kubernetes) rather than a shared writable volume.
Why โ A shared volume with several writers risks corruption and creates a single point of failure.
Interview tip โ Externalizing state is the real fix, not a clever volume.
Q64 How do you seed a new volume with initial data from an image?
Beginner
Situation read โ Docker populates an empty named volume from the image content at the mount path on first use.
What I'd do โ Put seed data at the path in the image, then docker run -v seed:/usr/share/app/data app. For databases use /docker-entrypoint-initdb.d/*.sql scripts which run only when the data directory is empty.
Why โ Population happens only for an empty named volume, not for bind mounts, which mask image content.
Interview tip โ A bind mount over a populated path hides the image's files.
Q65 Disk shows 95% full on /var/lib/docker. What do you check in order?
Intermediate
/var/lib/docker. What do you check in order?Situation read โ Typically images, build cache, container logs or volumes.
What I'd do โ
docker system df -v
du -xh --max-depth=2 /var/lib/docker | sort -h | tail
ls -lhS /var/lib/docker/containers/*/*-json.log | headThen prune images/build cache, truncate offending logs (truncate -s 0 <file>), and set max-size/max-file log options.
Why โ The json-file driver has no rotation by default.
Interview tip โ Fix the cause (log rotation), not only the symptom.
Q66 Choosing between --mount and -v.
Beginner
--mount and -v.Situation read โ Both attach storage.
What I'd do โ Prefer --mount type=volume,src=data,dst=/data,readonly: explicit key-value syntax, and it errors if a bind source path does not exist, whereas -v silently creates a root-owned directory.
Why โ Fewer surprises and clearer reviews.
Interview tip โ Compose long syntax mirrors --mount.
Q67 Persist a cache for CI jobs across runs on a self-hosted runner.
Intermediate
Situation read โ Repeated dependency downloads.
What I'd do โ Mount a named volume for ~/.cache/~/.m2 into job containers, or rely on BuildKit cache mounts on a persistent builder. Add size limits via builder GC (keepStorage) and key by lockfile hash when using external caches.
Why โ Persistent runners make local caches effective; ephemeral ones need remote caches.
Interview tip โ Beware cache poisoning between untrusted PR builds; isolate caches per trust level.
Q68 What happens to data when you run docker compose down vs down -v?
Beginner
docker compose down vs down -v?Situation read โ Common accident.
What I'd do โ docker compose down removes containers and networks but keeps named volumes. docker compose down -v also deletes named volumes declared in the file, and anonymous ones. Use stop if you only want to pause.
Why โ -v is destructive; bind mounts are never deleted.
Interview tip โ Say you guard prod hosts with backups and never run -v there.
Q69 Live-migrating a stateful container with minimal downtime.
Advanced
Situation read โ Docker does not support live migration (CRIU checkpoint is experimental).
What I'd do โ
- For a DB, set up replication to the new host, wait for lag zero, promote, repoint clients.
- For file-based state,
rsyncwhile running, then stop, finalrsync, start on the new host. - Lower DNS TTL beforehand.
Why โ Application-level replication is reliable; container checkpoint/restore is not production-grade.
Interview tip โ Mention podman container checkpoint exists but is niche.
Q70 A container writes huge files to /tmp and gets OOM-killed.
Intermediate
/tmp and gets OOM-killed.Situation read โ /tmp is probably tmpfs (counts as memory) or a mounted tmpfs.
What I'd do โ Move large temp files to a disk volume (-v scratch:/scratch) and set TMPDIR=/scratch, or cap tmpfs with size=. Confirm with docker inspect -f '{{.HostConfig.Tmpfs}}' c and df -h /tmp inside.
Why โ tmpfs pages are charged to the container's memory cgroup.
Interview tip โ Plain overlay /tmp is on disk; tmpfs only if explicitly mounted.
Q71 Sensitive data in a volume must be encrypted at rest.
Advanced
Situation read โ Docker volumes are plain directories.
What I'd do โ Encrypt below Docker: LUKS on the disk that holds /var/lib/docker or the volume path, or cloud-provider encrypted block storage (EBS with KMS). For app-level secrets use envelope encryption in the app or database TDE.
Why โ Docker itself has no volume encryption feature.
Interview tip โ Also mention key management: who unlocks LUKS on reboot.
Q72 Configuration files need to update without rebuilding the image.
Beginner
Situation read โ Config is separate from code.
What I'd do โ Mount it read-only: -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro, or in Compose use configs:. Reload without restart: docker exec web nginx -s reload.
Why โ Same image, different behaviour, and a simple rollback of config.
Interview tip โ Single-file bind mounts break on editors that replace the inode (vim); mount the directory.
Q73 How do you check what's changed inside a running container's filesystem?
Beginner
Situation read โ Need to find unexpected writes.
What I'd do โ
docker diff webOutput shows A (added), C (changed), D (deleted) paths versus the image.
Why โ Reveals what should be a volume or what an attacker modified.
Interview tip โ Good for forensics before you destroy the container.
Q74 A shared-NFS bind mount makes the app very slow.
Advanced
Situation read โ Metadata-heavy workloads (node_modules, PHP autoload) over NFS or macOS file sharing are slow.
What I'd do โ
- Keep dependencies inside the container (named volume for
node_modules/vendor). - On Docker Desktop use VirtioFS and
develop.watchsync. - Tune NFS (
nfsvers=4.1,noatime, largerrsize/wsize) for servers. - Measure with
fioorstrace -c.
Why โ Each stat becomes a network round trip.
Interview tip โ Local volumes are almost always faster than network mounts.
Q75 Retention for a volume holding uploaded user files.
Intermediate
Situation read โ Business data must survive host loss.
What I'd do โ Move to object storage (S3) with versioning, or replicate volume data via snapshot schedules (EBS, LVM snapshots) and off-host backups. Document RPO/RTO and run restore drills.
Why โ A single host volume is a single point of failure.
Interview tip โ Ask about RPO/RTO before choosing the design.
Networking and Compose
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q76 Containers on the default bridge cannot resolve each other by name. Why, and what do you do?
Beginner
Situation read โ The default bridge network has no embedded DNS for container names.
What I'd do โ
docker network create appnet
docker run -d --network appnet --name db postgres:17
docker run -d --network appnet --name api myapi # reach db at db:5432Compose does this automatically with a per-project network.
Why โ User-defined bridges provide automatic service discovery and better isolation.
Interview tip โ --link is legacy; do not use it.
Q77 How do you expose a container only to the local host, not the internet?
Beginner
Situation read โ -p 5432:5432 binds to 0.0.0.0 and Docker inserts iptables rules that bypass ufw.
What I'd do โ -p 127.0.0.1:5432:5432, or do not publish at all and let other containers connect over the Docker network. For Compose: ports: ["127.0.0.1:5432:5432"].
Why โ Published ports are DNAT'd in the DOCKER chain before most host firewall rules.
Interview tip โ Use the DOCKER-USER chain for custom filtering.
Q78 Design a Compose file for web + api + postgres + redis with correct startup ordering.
Intermediate
Situation read โ depends_on alone only waits for the container to start.
What I'd do โ
services:
db:
image: postgres:17
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 10
volumes: [pgdata:/var/lib/postgresql/data]
api:
build: ./api
depends_on:
db: { condition: service_healthy }
redis: { condition: service_started }
redis: { image: "redis:7" }
web:
image: nginx:1.27
ports: ["80:80"]
depends_on: [api]
volumes: { pgdata: {} }Why โ service_healthy gates on readiness, not just process start.
Interview tip โ Apps should still retry connections; ordering is best effort.
Q79 Frontend must reach the API but not the database. Segment the network.
Intermediate
Situation read โ Least-privilege networking.
What I'd do โ
services:
web: { networks: [front] }
api: { networks: [front, back] }
db: { networks: [back] }
networks:
front: {}
back: { internal: true }Why โ db shares no network with web; internal: true also blocks outbound internet for the back tier.
Interview tip โ Network aliases give stable names per network.
Q80 A container needs to call a service running on the Docker host.
Beginner
Situation read โ localhost inside the container is itself.
What I'd do โ Docker Desktop: use host.docker.internal. On Linux: --add-host=host.docker.internal:host-gateway (or Compose extra_hosts: ["host.docker.internal:host-gateway"]). The host service must listen on an address reachable from the bridge, not only 127.0.0.1.
Why โ The bridge gateway (usually 172.17.0.1) is the host from the container's view.
Interview tip โ --network host is an alternative but removes isolation.
Q81 When would you use --network host?
Intermediate
--network host?Situation read โ Needs maximum network performance or many dynamic ports.
What I'd do โ Use it for packet capture tools, node-level monitoring agents or high-throughput proxies on Linux. Do not combine with -p; those flags are ignored.
Why โ Skips NAT and veth overhead, but port conflicts with the host are possible and the container sees all host interfaces.
Interview tip โ It does not work the same on Docker Desktop (VM boundary).
Q82 Two Compose projects need to talk to each other.
Intermediate
Situation read โ Each project gets its own isolated network.
What I'd do โ Create a shared external network and attach both:
networks:
shared:
external: true
name: platform-netdocker network create platform-net once; services join with an explicit alias.
Why โ Explicit shared network avoids publishing ports just for inter-project calls.
Interview tip โ Name collisions on service names can occur; use aliases.
Q83 How do you route traffic to multiple Compose services by hostname?
Intermediate
Situation read โ One host, several web apps on port 80/443.
What I'd do โ Run a reverse proxy container (Traefik or Nginx Proxy Manager/Caddy) on a shared network. With Traefik use labels:
labels:
- "traefik.http.routers.api.rule=Host(`api.example.com`)"
- "traefik.http.services.api.loadbalancer.server.port=8080"Mount the Docker socket read-only into Traefik via a socket proxy.
Why โ Auto-discovery plus automated TLS (Let's Encrypt).
Interview tip โ Exposing the raw Docker socket to the proxy is a risk; use docker-socket-proxy.
Q84 You need a fixed IP for a container.
Intermediate
Situation read โ Some legacy firewalls or configs require static IPs.
What I'd do โ
docker network create --subnet 172.30.0.0/24 fixed
docker run --network fixed --ip 172.30.0.10 myappIn Compose, set ipam config and ipv4_address.
Why โ Static IPs only work on user-defined networks with a subnet.
Interview tip โ Prefer DNS names; static IPs signal tight coupling.
Q85 Docker's default subnet collides with the company VPN.
Intermediate
Situation read โ 172.17.0.0/16 or auto-assigned 172.18+ overlap with corporate ranges and break routing.
What I'd do โ Change in /etc/docker/daemon.json:
{
"bip": "10.200.0.1/24",
"default-address-pools": [{"base": "10.201.0.0/16", "size": 24}]
}Restart docker and recreate networks.
Why โ Pool applies to new networks; existing ones keep the old subnet.
Interview tip โ Plan address space with the network team up front.
Q86 How do you inspect which containers are attached to a network and their IPs?
Beginner
Situation read โ Need a quick topology view.
What I'd do โ
docker network ls
docker network inspect appnet \
--format '{{range .Containers}}{{.Name}} {{.IPv4Address}}{{"\n"}}{{end}}'Why โ Shows membership, subnet and gateway.
Interview tip โ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' c for one container.
Q87 Load balance three replicas on a single Docker host without Kubernetes.
Intermediate
Situation read โ Compose deploy.replicas works with docker compose up --scale.
What I'd do โ
docker compose up -d --scale api=3Do not publish a fixed host port on the scaled service; put nginx/Traefik in front, which resolves api via Docker DNS (round-robin across A records).
Why โ Docker's embedded DNS returns all replica IPs.
Interview tip โ Nginx caches DNS at start; use resolver 127.0.0.11 with a variable in proxy_pass.
Q88 Outbound HTTPS from containers works only through a corporate proxy.
Intermediate
Situation read โ Build and runtime need proxy settings; daemon pulls need them separately.
What I'd do โ
- Client side:
~/.docker/config.json"proxies": {"default": {"httpProxy": "...", "noProxy": "..."}}injects env vars into containers and builds. - Daemon pulls: systemd drop-in
Environment="HTTPS_PROXY=..."fordocker.service. - Install the corporate CA into base images.
Why โ The daemon, build containers and runtime containers are three separate places.
Interview tip โ Do not bake proxy settings into images.
Q89 Explain how you would debug a container with no shell and no network tools.
Advanced
Situation read โ Distroless image, need to run tcpdump or curl.
What I'd do โ
docker run --rm -it --network container:myapp --pid container:myapp \
nicolaka/netshoot
# or
docker debug myapp
# kubernetes
kubectl debug -it pod/myapp --image=nicolaka/netshoot --target=myappWhy โ Joining the target's network (and PID) namespace gives full tooling without changing the image.
Interview tip โ Never install tools into prod images "just for debugging".
Q90 IPv6 is needed for containers.
Intermediate
Situation read โ Docker IPv6 is off by default.
What I'd do โ In daemon.json: {"ipv6": true, "fixed-cidr-v6": "2001:db8:1::/64"} (with ip6tables: true on recent versions) and for user networks docker network create --ipv6 --subnet 2001:db8:2::/64 v6net. Verify routing and firewall for the prefix.
Why โ Docker must hand out routable or NAT'd v6 addresses.
Interview tip โ Recent Docker releases (27+) improved IPv6 and ip6tables support.
Q91 Which Compose features do you use for local dev vs production?
Intermediate
Situation read โ Same services, different needs.
What I'd do โ Base compose.yaml holds services; compose.override.yaml (auto-loaded) adds bind mounts, debug ports and develop.watch; compose.prod.yaml sets restart: unless-stopped, resource limits and no bind mounts: docker compose -f compose.yaml -f compose.prod.yaml up -d. Use profiles for optional tools.
Why โ Layered files avoid duplication.
Interview tip โ docker compose config shows the merged result.
Q92 The app works with docker run but inside Compose cannot read an env var.
Beginner
docker run but inside Compose cannot read an env var.Situation read โ Compose interpolates ${VAR} from the shell and .env; environment: and env_file: differ.
What I'd do โ Check with docker compose config to see resolved values; use env_file: .env.app for container env and .env for substitution in the compose file itself. Quote values with spaces.
Why โ .env is for Compose-file variables unless you also list it under env_file.
Interview tip โ Precedence: shell > environment > env_file > image ENV.
Q93 How do you handle secrets in Compose?
Intermediate
Situation read โ Env vars leak in docker inspect and logs.
What I'd do โ
services:
api:
secrets: [db_password]
environment: { DB_PASSWORD_FILE: /run/secrets/db_password }
secrets:
db_password: { file: ./secrets/db_password.txt }App reads the file at start. Keep the secrets directory out of git.
Why โ Mounted as a read-only tmpfs file at /run/secrets.
Interview tip โ In production use a secret manager (Vault, AWS Secrets Manager).
Q94 Expose container port range dynamically and discover the mapping.
Beginner
Situation read โ Several instances on one host, avoiding port clashes.
What I'd do โ
docker run -d -p 8080 myapp # random host port
docker port <container> 8080Or -P to publish all EXPOSEd ports to random ports.
Why โ EXPOSE is documentation only; -p/-P actually publishes.
Interview tip โ A common trick question.
Q95 You need containers on different hosts to communicate privately.
Advanced
Situation read โ Bridge networks are host-local.
What I'd do โ Docker Swarm overlay network (docker network create -d overlay --attachable --opt encrypted app), which uses VXLAN on UDP 4789 plus ports 2377/7946. Otherwise use Kubernetes CNI, or WireGuard mesh between hosts.
Why โ Overlay encapsulates traffic across hosts; --opt encrypted adds IPsec at a CPU cost.
Interview tip โ Open firewall ports 2377/tcp, 7946/tcp+udp, 4789/udp.
Q96 Make a database reachable only by the app, and the app only through a reverse proxy, on a single host.
Intermediate
Situation read โ Minimise published ports.
What I'd do โ Publish only the proxy (80/443). DB and app have no ports: entries and sit on private networks. Verify:
docker compose ps --format '{{.Name}} {{.Ports}}'
ss -tlnp | grep docker-proxyWhy โ Unpublished services are unreachable from outside the Docker networks.
Interview tip โ Scan the host with nmap to confirm.
Q97 Explain what Docker does with iptables when you publish a port.
Advanced
Situation read โ Interviewers probe whether you know why ufw doesn't block it.
What I'd do โ Inspect:
iptables -t nat -L DOCKER -n
iptables -L DOCKER-USER -nDocker adds a DNAT rule in the nat table for -p, a MASQUERADE for egress, and forwarding rules in filter. Place your restrictions in DOCKER-USER, which is evaluated first.
Why โ Traffic is DNAT'd in PREROUTING and goes through FORWARD, never reaching the INPUT chain where ufw typically sits. Newer engines can use nftables (experimental in 29).
Interview tip โ Bind published ports to specific IPs as the simplest control.
Q98 Run a one-off migration job with Compose without keeping the container.
Beginner
Situation read โ Need to run a command once in the service context.
What I'd do โ
docker compose run --rm api python manage.py migrateUse profiles: ["tools"] so it does not start with up.
Why โ run creates a new container using the service config, --rm removes it afterwards, while exec attaches to a running one.
Interview tip โ Use exec for running containers, run for fresh ones.
Q99 Compose healthcheck for a service depends on the app being ready, not just the port open.
Intermediate
Situation read โ A TCP-open port can still return 503.
What I'd do โ
healthcheck:
test: ["CMD", "curl", "-fsS", "http://localhost:8080/healthz"]
interval: 10s
timeout: 3s
retries: 5
start_period: 30sMake /healthz check dependencies (cache or DB) with care, since cascading failures can occur.
Why โ -f makes curl fail on HTTP errors; start_period avoids false negatives during boot.
Interview tip โ Separate liveness from readiness semantics.
Q100 Which DNS settings do you adjust when containers cannot resolve internal company hosts?
Intermediate
Situation read โ Containers on user-defined networks use Docker's embedded DNS at 127.0.0.11, forwarding to the host's resolvers; with systemd-resolved the host stub 127.0.0.53 is unusable.
What I'd do โ
{"dns": ["10.0.0.2"], "dns-search": ["corp.example.com"]}in daemon.json, or per run --dns 10.0.0.2 --dns-search corp.example.com. Test with docker run --rm busybox nslookup intranet.corp.example.com.
Why โ Docker substitutes the real upstream resolvers from /run/systemd/resolve/resolv.conf.
Interview tip โ Check VPN split-DNS interactions.
Security and scanning
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q101 A scan reports 300 CVEs in your base image. How do you triage?
Intermediate
Situation read โ Raw counts are noise; exploitability and fixability matter.
What I'd do โ
trivy image --severity HIGH,CRITICAL --ignore-unfixed app:1.8.2.- Separate OS packages from app dependencies and see which are actually in the runtime path.
- Rebuild on a newer base or move to slim/distroless to drop unused packages.
- Use VEX statements or
.trivyignorewith expiry and justification for accepted risks.
Why โ Most CVEs live in packages the app never loads.
Interview tip โ Fix by removing packages first, patching second.
Q102 Add vulnerability scanning to CI so critical findings block the merge.
Beginner
Situation read โ Shift-left gating.
What I'd do โ
trivy image --exit-code 1 --severity CRITICAL --ignore-unfixed app:$SHA
# or
grype app:$SHA --fail-on high
# or
docker scout cves --exit-code --only-severity critical,high app:$SHAAlso scan the Dockerfile with hadolint and IaC with trivy config.
Why โ Exit code fails the pipeline; scheduled rescans catch newly disclosed CVEs.
Interview tip โ A passing scan today does not mean safe tomorrow; rescan deployed images.
Q103 Why is mounting /var/run/docker.sock into a container dangerous?
Intermediate
/var/run/docker.sock into a container dangerous?Situation read โ CI agents and dashboards often ask for it.
What I'd do โ Treat socket access as root on the host: anyone can start a privileged container mounting /. Alternatives: rootless Docker or Podman for CI, Kaniko/BuildKit/buildah for in-cluster builds, a socket proxy that allows only specific API calls, or Sysbox/DinD in a sandbox.
Why โ The API has no per-call authorization by default.
Interview tip โ Show the one-liner: docker run -v /:/host --privileged ... is possible with the socket.
Q104 A developer asks for --privileged. What do you do?
Intermediate
--privileged. What do you do?Situation read โ Usually only a few capabilities or devices are needed.
What I'd do โ Ask what for. Replace with the narrow need: --cap-add NET_ADMIN, --device /dev/fuse, --cap-add SYS_PTRACE for debugging. For Docker-in-Docker use rootless DinD or Sysbox.
Why โ --privileged gives all capabilities, disables seccomp/AppArmor and exposes host devices.
Interview tip โ Start from --cap-drop ALL and add back.
Q105 Harden a container run command for a stateless web API.
Intermediate
Situation read โ Apply defense in depth.
What I'd do โ
docker run -d --name api \
--read-only --tmpfs /tmp \
--cap-drop ALL \
--security-opt no-new-privileges:true \
--pids-limit 200 --memory 512m --cpus 1 \
--user 10001:10001 \
-p 127.0.0.1:8080:8080 myapi:1.8.2Why โ Each flag removes a class of post-exploitation action.
Interview tip โ Mention keeping the default seccomp profile on and not disabling it.
Q106 A pentester got root inside a container. How bad is it?
Advanced
Situation read โ Depends on isolation settings.
What I'd do โ Check: is it privileged? docker.sock mounted? host PID/net namespace? sensitive host paths bind-mounted? dangerous capabilities (SYS_ADMIN, SYS_MODULE)? kernel version (container escapes like runc CVEs)? If none, root in the container is still uid 0 mapped to host root unless userns is on, but confined by namespaces, cgroups, seccomp and capabilities.
Why โ Container root is not host root only because of those layers.
Interview tip โ Use capsh --print and cat /proc/self/status | grep Cap inside to assess.
Q107 Choose a base image strategy for security across the company.
Advanced
Situation read โ Hundreds of images, inconsistent bases.
What I'd do โ Standardize on minimal maintained bases (distroless, Chainguard, Docker Hardened Images, or Alpine/Debian slim), mirror them, rebuild nightly, sign, SBOM and attach attestations. Block unapproved registries in admission control.
Why โ Fewer packages mean fewer CVEs and faster patching, and a central pipeline gives one patch point.
Interview tip โ Explain the tradeoff: debuggability versus attack surface.
Q108 How do you generate and use an SBOM for images?
Intermediate
Situation read โ When a new CVE like Log4Shell drops, you need to know which images contain it.
What I'd do โ
syft app:1.8.2 -o spdx-json > sbom.spdx.json
docker buildx build --sbom=true --push -t reg/app:1.8.2 .
grype sbom:sbom.spdx.jsonStore SBOMs next to images (attached as OCI attestations) and index them.
Why โ Query inventory instead of rescanning everything.
Interview tip โ cosign attest --type spdxjson signs the SBOM.
Q109 How do you prevent a container from gaining privileges via setuid binaries?
Intermediate
Situation read โ setuid binaries like su or ping can be abused.
What I'd do โ --security-opt no-new-privileges:true and strip setuid bits in the image: RUN find / -perm /6000 -type f -exec chmod a-s {} + || true. Drop capabilities.
Why โ no-new-privileges sets the kernel flag so execve cannot raise privileges.
Interview tip โ In Kubernetes: allowPrivilegeEscalation: false.
Q110 Customize seccomp for an app that needs one blocked syscall.
Advanced
Situation read โ Docker's default profile blocks about 50 syscalls (e.g., ptrace on older kernels, mount, keyctl).
What I'd do โ
- Save the default profile, add only the required syscall to the allow list.
docker run --security-opt seccomp=./profile.json app.- Find needed calls with
strace -c -fordocker run --security-opt seccomp=unconfinedonly in a test.
Why โ A tailored profile is safer than unconfined.
Interview tip โ Never ship seccomp=unconfined.
Q111 Secrets showing up in docker inspect output of production containers.
Beginner
docker inspect output of production containers.Situation read โ Passed as -e DB_PASSWORD=...; anyone with Docker access can read them, and they land in shell history and CI logs.
What I'd do โ Use secrets files (/run/secrets), --env-file with strict permissions at minimum, or fetch at start from Vault/AWS SM. Restrict Docker API access and rotate leaked values.
Why โ docker inspect reveals .Config.Env in plain text.
Interview tip โ Orchestrator-native secrets beat env vars.
Q112 Enforce that only signed images from your registry can run on hosts.
Advanced
Situation read โ Docker Engine alone has Docker Content Trust (Notary v1) which is legacy.
What I'd do โ In Kubernetes use an admission policy (Kyverno verifyImages, Sigstore policy-controller, Ratify/Gatekeeper). On standalone hosts configure containerd/Podman policy.json with sigstoreSigned requirements and restrict registries.
Why โ Enforcement must happen at pull/admission time, not in docs.
Interview tip โ Mention that DCT is deprecated in favor of Sigstore/cosign.
Q113 Review a Dockerfile: FROM ubuntu, RUN curl ... | bash, no USER. What are your comments?
Beginner
FROM ubuntu, RUN curl ... | bash, no USER. What are your comments?Situation read โ Several smells.
What I'd do โ
- Pin base tag/digest, prefer a smaller base.
- Do not pipe remote scripts to bash; download, verify checksum, then run.
- Add a non-root
USER. - Combine layers, clean caches.
- Add
HEALTHCHECKand.dockerignore; runhadolint.
Why โ Unverified downloads are a supply-chain risk.
Interview tip โ Lead with the security items, then efficiency.
Q114 Run untrusted code (CI jobs from forks) safely with Docker.
Advanced
Situation read โ Standard containers share the host kernel.
What I'd do โ Use stronger isolation: gVisor (--runtime=runsc), Kata Containers or Firecracker microVMs, ephemeral runners per job, no socket mounts, no secrets for fork PRs, egress filtering and resource limits.
Why โ Kernel exploits cross standard container boundaries; sandboxes reduce that surface.
Interview tip โ Isolation level should match trust level.
Q115 Keep Docker daemon API from being exposed insecurely.
Intermediate
Situation read โ -H tcp://0.0.0.0:2375 gives unauthenticated root to the network (cryptominers love it).
What I'd do โ Use the Unix socket locally, or SSH (DOCKER_HOST=ssh://user@host), or TLS with client certs on 2376 (--tlsverify). Firewall the port and audit with ss -tlnp | grep dockerd.
Why โ Remote API equals remote root.
Interview tip โ docker context create makes SSH access ergonomic.
Q116 How do you apply AppArmor or SELinux with Docker?
Advanced
Situation read โ Mandatory access control adds a second barrier.
What I'd do โ Ubuntu: default docker-default AppArmor profile is applied automatically; custom: --security-opt apparmor=myprofile. RHEL/Fedora: enable "selinux-enabled": true in daemon.json, label mounts with :z/:Z, and keep container_t confinement.
Why โ Even if processes escape other controls, MAC denies access outside policy.
Interview tip โ Never run setenforce 0 to fix a mount error; fix labels.
Q117 Detect drift: a running container behaves differently than its image.
Advanced
Situation read โ Possible compromise or unmanaged changes.
What I'd do โ docker diff, compare running processes (docker top), check network connections (ss -tnp inside netns via nsenter), then use runtime tools (Falco, Tetragon) to alert on unexpected exec/file writes. Make containers read-only to turn drift into failures.
Why โ Immutability makes anomalies loud.
Interview tip โ Snapshot with docker export for forensics before killing it.
Q118 Scan an image that is already deployed, without rebuilding it.
Beginner
Situation read โ New CVEs appear after deployment.
What I'd do โ Scan by digest from the registry (trivy image reg/app@sha256:...), schedule daily scans in the registry (ECR enhanced scanning, Harbor, Docker Scout) and alert owners. Rebuild and redeploy when fixes exist.
Why โ Vulnerabilities are discovered over time; images are static.
Interview tip โ Track MTTR for patching images as a KPI.
Q119 What do you do about Dockerfile ADD https://... with no checksum?
Intermediate
ADD https://... with no checksum?Situation read โ Unverified remote content.
What I'd do โ
ADD --checksum=sha256:9f86d0... https://example.com/tool.tar.gz /tmp/or curl and sha256sum -c. Prefer package managers with signature verification.
Why โ Prevents tampering and silent upstream changes.
Interview tip โ Same principle for go install or pip install from unpinned sources.
Q120 User namespaces: when would you enable userns-remap?
Advanced
userns-remap?Situation read โ You want container root to map to an unprivileged host UID without going fully rootless.
What I'd do โ Set {"userns-remap": "default"} in daemon.json; Docker creates dockremap and uses /etc/subuid. Be aware: images and volumes get re-owned under a separate storage dir, and features like --privileged, host networking and some volume drivers are restricted.
Why โ Root escape lands as a non-root UID on the host.
Interview tip โ Rootless mode is the stronger alternative for new setups.
Q121 How do you handle the Docker group on shared servers?
Beginner
Situation read โ Membership of docker group equals root.
What I'd do โ Keep it to a minimal set of admins, use rootless Docker or Podman for developers, or sudo with logging. Audit with getent group docker and enable auditd rules on /usr/bin/dockerd and the socket.
Why โ The group grants full control of the daemon.
Interview tip โ Say "docker group is passwordless root."
Q122 Proving which source commit and builder produced an image (SLSA).
Advanced
Situation read โ Supply-chain audit requirement.
What I'd do โ Build with BuildKit provenance (--provenance=mode=max), or the SLSA GitHub generator, and sign using cosign keyless. Verify with cosign verify-attestation --type slsaprovenance ... or gh attestation verify oci://reg/app@sha256:... -R org/repo.
Why โ Provenance links artifact to builder identity and source.
Interview tip โ Aim for SLSA Level 3 with isolated, ephemeral builders.
Q123 Reduce capabilities for an nginx container that binds port 80 as non-root.
Intermediate
Situation read โ nginx master needs a few caps for root start; unprivileged variant avoids them.
What I'd do โ Use nginxinc/nginx-unprivileged listening on 8080, then --cap-drop ALL. If binding low ports is mandatory, --cap-add NET_BIND_SERVICE or --sysctl net.ipv4.ip_unprivileged_port_start=80.
Why โ Minimal capabilities with no root user reduce risk.
Interview tip โ Publish -p 80:8080 on the host side instead.
Q124 Stop leaking build-time secrets through docker history in an existing pipeline.
Intermediate
docker history in an existing pipeline.Situation read โ Old Dockerfiles use ARG TOKEN and RUN git clone https://$TOKEN@....
What I'd do โ Replace with RUN --mount=type=secret,id=gh_token ... or --mount=type=ssh; rotate leaked tokens; purge old tags; add a Trivy secret scan to CI.
Why โ ARG values are stored in image metadata and visible in history.
Interview tip โ Rotate first.
Q125 Compliance wants evidence that containers do not run as root.
Intermediate
Situation read โ Need automated audit.
What I'd do โ
docker ps -q | xargs docker inspect -f '{{.Name}} user={{.Config.User}} priv={{.HostConfig.Privileged}}'Build a CI check with hadolint rule DL3002, trivy config, and in Kubernetes enforce Pod Security Standards "restricted" or Kyverno policy require-run-as-nonroot. Run docker-bench-security for the host.
Why โ Policy-as-code produces repeatable evidence.
Interview tip โ CIS Docker Benchmark is the common reference.
Limits, logging, health checks and restarts
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q126 A Java container is OOM-killed at 512 MB. Why isn't the heap the whole story?
Intermediate
Situation read โ JVM memory includes heap, metaspace, thread stacks, code cache and native buffers.
What I'd do โ
- Use container-aware flags:
-XX:MaxRAMPercentage=70. - Check
docker inspect -f '{{.State.OOMKilled}}' canddmesg | grep -i oom. - Add native memory tracking
-XX:NativeMemoryTracking=summaryand size the limit accordingly.
Why โ The cgroup counts total RSS, not just heap.
Interview tip โ Leave 25โ30% headroom above heap.
Q127 How do you cap CPU and memory for a container and what happens on exceed?
Beginner
Situation read โ Resource governance.
What I'd do โ
docker run -d --memory 512m --memory-swap 512m --cpus 1.5 myappCPU over the limit is throttled (CFS quota); memory over the limit triggers the kernel OOM killer for that cgroup.
Why โ Setting --memory-swap equal to --memory disables swap use.
Interview tip โ CPU = throttling, memory = kill.
Q128 Latency spikes though CPU usage looks low (50%).
Advanced
Situation read โ CFS throttling can occur in bursts even at modest averages.
What I'd do โ Check cat /sys/fs/cgroup/cpu.stat inside the container (cgroup v2) for nr_throttled and throttled_usec. Raise or remove the CPU limit, use --cpu-shares/requests only, or tune the app's thread pools to match --cpus.
Why โ A multi-threaded app can burn its 100 ms quota in 20 ms and then stall.
Interview tip โ Many teams set requests but no CPU limits for this reason.
Q129 docker logs is empty but the app is running.
Beginner
docker logs is empty but the app is running.Situation read โ The app logs to a file, not stdout/stderr, or the logging driver is not json-file/local.
What I'd do โ docker inspect -f '{{.HostConfig.LogConfig.Type}}' c; docker exec c ls -l /var/log. Redirect to stdout (ln -sf /dev/stdout /var/log/app.log) or configure app logging.
Why โ docker logs reads only for drivers that support it (e.g. not syslog before newer dual-logging).
Interview tip โ Dual logging in 20.10+ keeps docker logs working with remote drivers.
Q130 Configure log rotation globally.
Beginner
Situation read โ Default json-file logs grow unbounded.
What I'd do โ
{
"log-driver": "local",
"log-opts": {"max-size": "20m", "max-file": "5"}
}in /etc/docker/daemon.json; systemctl restart docker. Existing containers need recreation.
Why โ The local driver compresses and rotates by default.
Interview tip โ Changes apply only to new containers.
Q131 Ship container logs to a central system.
Intermediate
Situation read โ Hosts are ephemeral, logs must be centralised.
What I'd do โ Options: run a collector (Fluent Bit, Vector, Promtail/Alloy) tailing /var/lib/docker/containers/*/*-json.log with Docker metadata; or use a driver (fluentd, gelf, awslogs, loki plugin). Collector approach is more resilient because blocking drivers can stall the app.
Why โ The default blocking log mode can slow the app if the remote is down; set mode=non-blocking with max-buffer-size.
Interview tip โ Structured JSON logs make queries easy.
Q132 Define a good restart policy for a production service.
Beginner
Situation read โ Containers should survive crashes and reboots.
What I'd do โ --restart unless-stopped (or always); on-failure:5 for batch jobs. In Compose: restart: unless-stopped.
Why โ unless-stopped honours an operator's explicit stop across daemon restarts, while always restarts regardless. Backoff doubles up to 1 minute for repeated failures.
Interview tip โ Restart policy is not orchestration; it will not reschedule on another host.
Q133 Container is in a restart loop. How do you triage quickly?
Beginner
Situation read โ Process exits immediately and restart policy keeps trying.
What I'd do โ
docker ps -a
docker logs --tail 100 c
docker inspect -f '{{.State.ExitCode}} {{.State.OOMKilled}} {{.State.Error}}' cRun it without restart policy and with an overridden entrypoint: docker run --rm -it --entrypoint sh image.
Why โ Exit code 137 = SIGKILL (OOM?), 1 = app error, 126/127 = command not executable/not found.
Interview tip โ Read exit codes fluently.
Q134 Health check marks a container unhealthy but nothing restarts it.
Intermediate
Situation read โ Plain Docker only labels health; it doesn't act on it.
What I'd do โ Use Swarm (restarts unhealthy tasks), Kubernetes probes, or a watcher such as autoheal container, or systemd Restart= plus docker kill hooks. Compose depends_on: condition: service_healthy uses it for ordering only.
Why โ The engine records state healthy/unhealthy for orchestrators to use.
Interview tip โ This is a classic trick question.
Q135 Tune a health check for a slow-starting app (2 minutes boot).
Intermediate
Situation read โ Early failures would mark it unhealthy.
What I'd do โ
HEALTHCHECK --start-period=150s --interval=10s --timeout=3s --retries=3 \
CMD wget -qO- http://localhost:8080/healthz || exit 1Why โ Failures during start-period don't count toward retries, and the first success ends it.
Interview tip โ Make sure wget/curl exists in the image.
Q136 A batch container should use at most 2 CPUs on a 32-core node, and pin to specific cores.
Intermediate
Situation read โ Noisy neighbours or NUMA concerns.
What I'd do โ --cpus 2 (quota) or --cpuset-cpus 0-1 (pinning). Use cpuset for latency-sensitive workloads and quota for fair sharing. Check inside with nproc (reflects cpuset not quota).
Why โ Quota limits time; cpuset limits which cores.
Interview tip โ Apps reading nproc size thread pools by cpuset, not quota.
Q137 Prevent a fork bomb in a container.
Intermediate
Situation read โ Unbounded PIDs can exhaust the host process table.
What I'd do โ docker run --pids-limit 256 ... and a daemon default via "default-pids-limit" where supported. Add --ulimit nofile=65536:65536 for file descriptors.
Why โ The pids cgroup controller stops fork calls beyond the limit.
Interview tip โ Test with :(){ :|:& };: in a sandbox.
Q138 Compose limits: where do you set CPU/memory in Compose v2?
Intermediate
Situation read โ Old mem_limit vs deploy.resources.
What I'd do โ
services:
api:
deploy:
resources:
limits: { cpus: "1.0", memory: 512M }
reservations: { memory: 256M }Modern docker compose applies deploy.resources without Swarm. Verify with docker stats and docker inspect.
Why โ One syntax across Compose and Swarm.
Interview tip โ Reservation is a soft guarantee; limit is a hard cap.
Q139 Memory usage seems to grow in docker stats but the app is fine.
Advanced
docker stats but the app is fine.Situation read โ Page cache counts toward the cgroup's usage.
What I'd do โ Compare memory.current with memory.stat (anon vs file) in /sys/fs/cgroup. Newer docker stats subtracts inactive file cache. Alert on working set and OOM events, not raw usage.
Why โ Reclaimable cache is freed under pressure; it isn't a leak.
Interview tip โ Working set = usage minus inactive_file.
Q140 Graceful shutdown with a 60-second drain for in-flight requests.
Intermediate
Situation read โ Default stop timeout is 10 s.
What I'd do โ Handle SIGTERM in the app (stop accepting, finish requests), then docker stop -t 60 or Compose stop_grace_period: 60s. Set STOPSIGNAL SIGQUIT for nginx-style graceful stop.
Why โ Docker sends the stop signal, waits, then SIGKILL.
Interview tip โ Verify the process is PID 1 or forwards signals.
Q141 Monitor containers in production, what do you collect?
Intermediate
Situation read โ Need metrics, logs and events.
What I'd do โ cAdvisor or the engine's Prometheus endpoint ("metrics-addr": "127.0.0.1:9323") for container metrics, node exporter for hosts, logs via Fluent Bit/Loki, alerts on restarts, OOM kills, unhealthy status and throttling. docker events --filter type=container for live events.
Why โ Restarts and OOMs are the earliest failure signals.
Interview tip โ Alert on rate of restarts, not individual ones.
Q142 Different log formats from many containers are hard to query.
Beginner
Situation read โ Unstructured text.
What I'd do โ Standardize on JSON logs (timestamp, level, service, trace_id) from the app and let the collector add container labels. Use Docker labels/tag log option to add metadata: --log-opt tag="{{.Name}}".
Why โ Consistent fields enable dashboards and alerts.
Interview tip โ Correlation IDs across services are the payoff.
Q143 A container's clock drifts or time jumps.
Advanced
Situation read โ Containers use the host kernel clock; there is no per-container clock (except time namespaces, not used by Docker by default).
What I'd do โ Fix NTP/chrony on the host. On Docker Desktop, restart the VM after sleep. Never run an NTP daemon inside a normal container (SYS_TIME needed).
Why โ One kernel clock per host or VM.
Interview tip โ Mention Docker Desktop VM drift after laptop sleep.
Q144 Set ulimits for a database container that needs many file descriptors.
Intermediate
Situation read โ Default nofile may be too low (or very high in newer systemd setups causing slowdowns).
What I'd do โ
docker run --ulimit nofile=65536:65536 --ulimit memlock=-1:-1 dbIn Compose, ulimits: key. Verify with docker exec db sh -c 'ulimit -n'.
Why โ Limits are per-process rlimits set at container start.
Interview tip โ Elasticsearch needs vm.max_map_count set on the host, not in the container.
Q145 How do you restrict disk IO of a noisy container?
Advanced
Situation read โ Backup job saturates disk.
What I'd do โ --device-read-bps /dev/nvme0n1:50mb --device-write-bps /dev/nvme0n1:50mb or --device-write-iops. Works on cgroup v2 hosts with the io controller, for block devices (not volumes on network filesystems).
Why โ Throttles throughput per device.
Interview tip โ Use the underlying device name from lsblk.
Q146 Which cgroup version are you on and why does it matter?
Intermediate
Situation read โ Some images or tools assume v1 paths.
What I'd do โ
stat -fc %T /sys/fs/cgroup # cgroup2fs => v2
docker info | grep -i cgroupUpdate old monitoring agents and JVMs (JDK 15+/8u372+ understand v2).
Why โ v2 is the unified hierarchy, default on modern distros, and gives better memory/IO accounting.
Interview tip โ Old Java versions ignoring v2 limits was a notorious pitfall.
Q147 Containers should start automatically after a host reboot, but not a one-off debug container.
Beginner
Situation read โ Restart policies plus the Docker service enabled.
What I'd do โ systemctl enable docker, run services with --restart unless-stopped, debug containers with --rm and no policy. Check with docker inspect -f '{{.HostConfig.RestartPolicy.Name}}' c.
Why โ Restart policy applies when the daemon starts.
Interview tip โ live-restore keeps containers up during daemon restarts.
Q148 Explain live-restore and when to use it.
Advanced
live-restore and when to use it.Situation read โ Daemon upgrades would otherwise stop all containers.
What I'd do โ Set {"live-restore": true} in daemon.json, systemctl reload docker (SIGHUP), then upgrades or restarts of dockerd leave containers running (containerd-shim keeps them). Not supported in Swarm mode and certain config changes still need container recreation.
Why โ Reduces downtime during patching.
Interview tip โ Cannot be combined with Swarm.
Q149 Alert when a container hits OOM.
Intermediate
Situation read โ Need signal before customers complain.
What I'd do โ Subscribe: docker events --filter event=oom, scrape cAdvisor metric container_oom_events_total, and alert from Prometheus. Also watch container_memory_working_set_bytes / limit > 0.9.
Why โ OOM kill leaves exit code 137 and OOMKilled=true only until the container is removed.
Interview tip โ Alert on approach, not only on death.
Q150 Detect and handle zombie processes in a container.
Intermediate
Situation read โ PID 1 doesn't reap orphaned children, so ps shows <defunct>.
What I'd do โ docker run --init (tini) or Compose init: true; or bake tini in the image as ENTRYPOINT. Verify: docker exec c ps -eo pid,ppid,stat,cmd | grep Z.
Why โ An init reaps children and forwards signals.
Interview tip โ Tini is bundled with Docker since 1.13.
Runtimes: containerd, OCI, rootless and Podman
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q151 Explain the path from docker run to a running process.
Intermediate
docker run to a running process.Situation read โ A layered architecture question.
What I'd do โ Walk the chain: docker CLI โ REST API on dockerd โ containerd (images, snapshots, lifecycle) โ containerd-shim-runc-v2 (one per container/pod) โ runc (creates namespaces, cgroups, execs the process, then exits). The shim keeps stdio and reports exit status.
ps -ef --forest | grep -E 'dockerd|containerd|runc'Why โ The shim lets the daemon restart without killing containers.
Interview tip โ runc is the reference OCI runtime implementation.
Q152 Kubernetes removed dockershim. What does that mean for your Docker-built images?
Beginner
Situation read โ Common confusion.
What I'd do โ Nothing changes for images: they are OCI images and run on containerd or CRI-O. Only the Docker Engine as a node runtime was removed in 1.24 (use cri-dockerd if you truly need it). Replace docker ps on nodes with crictl ps or nerdctl.
Why โ Image and runtime specs are standardized.
Interview tip โ "Docker images yes, Docker daemon on nodes no."
Q153 Run rootless Docker for developers on a shared Linux box.
Intermediate
Situation read โ Remove the root-equivalent daemon.
What I'd do โ
sudo apt-get install -y uidmap docker-ce-rootless-extras
dockerd-rootless-setuptool.sh install
systemctl --user enable --now docker
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
loginctl enable-linger $USERCheck /etc/subuid and /etc/subgid ranges exist.
Why โ The daemon and containers run in a user namespace; a breakout lands as an unprivileged user.
Interview tip โ Limits: ports below 1024, some network modes and --privileged-style features.
Q154 Podman vs Docker: when would you pick Podman?
Intermediate
Situation read โ Choose by constraints.
What I'd do โ Podman: daemonless, rootless by default, fork/exec model, systemd integration (Quadlet), pods, runs well on RHEL/Fedora. Docker: ecosystem, Compose maturity, Desktop experience, Swarm. CLI is mostly compatible (alias docker=podman); podman compose or docker-compose with the Podman socket handles Compose files.
Why โ No central daemon means no single root-owned process to attack or crash.
Interview tip โ Both consume OCI images and Dockerfiles (Containerfile).
Q155 Run a Podman container as a systemd service.
Intermediate
Situation read โ Replace Docker's restart policy with systemd.
What I'd do โ Use Quadlet. Create ~/.config/containers/systemd/web.container:
[Container]
Image=docker.io/library/nginx:1.27
PublishPort=8080:80
[Service]
Restart=always
[Install]
WantedBy=default.targetsystemctl --user daemon-reload && systemctl --user start web.serviceWhy โ podman generate systemd is deprecated in favor of Quadlet.
Interview tip โ Run loginctl enable-linger for boot-time user services.
Q156 What is the OCI and which specs does it define?
Beginner
Situation read โ Foundational standards question.
What I'd do โ The Open Container Initiative defines three specs: Runtime Spec (config.json and lifecycle for bundles, implemented by runc, crun, youki, gVisor), Image Spec (layers, config, manifest) and Distribution Spec (registry API).
Why โ Interoperability: build with BuildKit, store in any registry, run with any runtime.
Interview tip โ Mention Docker v2 schema 2 manifests are close cousins of OCI manifests.
Q157 Compare runc, crun, gVisor and Kata.
Advanced
runc, crun, gVisor and Kata.Situation read โ Runtime selection by isolation need.
What I'd do โ runc (Go, default), crun (C, faster start, lower memory, default in Podman on Fedora), runsc/gVisor (user-space kernel intercepting syscalls, stronger isolation, syscall overhead), Kata (each container/pod in a lightweight VM, strongest isolation, higher startup and memory cost). Select via --runtime or Kubernetes RuntimeClass.
Why โ Trade isolation against performance and compatibility.
Interview tip โ Match the runtime to the tenant trust level.
Q158 Use nerdctl or ctr or crictl?
Intermediate
nerdctl or ctr or crictl?Situation read โ On a containerd node, which CLI?
What I'd do โ crictl for Kubernetes node debugging (CRI view: pods, containers, crictl logs). nerdctl for a Docker-like experience on containerd (Compose, build with BuildKit). ctr is a low-level debug tool and not meant for daily use. Namespaces: Kubernetes uses k8s.io, so ctr -n k8s.io images ls.
Why โ Each has a different abstraction level.
Interview tip โ Know the -n k8s.io namespace.
Q159 Move from Docker Engine to containerd on a standalone host.
Advanced
Situation read โ Fewer moving parts, no dockerd.
What I'd do โ
- Install containerd, CNI plugins, BuildKit and
nerdctl. - Replace
docker runflags (mostly compatible) anddocker composewithnerdctl compose. - Configure
/etc/containerd/config.toml(SystemdCgroup = true, registry mirrors). - Migrate images with
docker save | nerdctl load. - Run side by side for a canary workload first.
Why โ Smaller attack surface; same runtime Kubernetes uses.
Interview tip โ Not every Docker feature exists (Swarm, some plugins).
Q160 Explain OCI image layout: manifest, config, layers.
Intermediate
Situation read โ Know the data model.
What I'd do โ Manifest lists config digest and ordered layer digests with media types; the config JSON holds env, entrypoint, rootfs diff_ids and history; each layer is a compressed tar of filesystem changes (with whiteout files for deletes). An index (manifest list) points to per-platform manifests.
skopeo copy docker://alpine:3.20 oci:/tmp/alpine:3.20
cat /tmp/alpine/index.json | jqWhy โ Content addressing gives deduplication and integrity.
Interview tip โ Layer digest (compressed) differs from diff_id (uncompressed).
Q161 A rootless Podman container cannot bind port 80.
Intermediate
Situation read โ Unprivileged users cannot bind ports below 1024 by default.
What I'd do โ sudo sysctl -w net.ipv4.ip_unprivileged_port_start=80 (persist in /etc/sysctl.d/), or publish 8080 and front it with a reverse proxy or socket activation.
Why โ Kernel restriction on privileged ports.
Interview tip โ The sysctl affects all users; document it.
Q162 Generate Kubernetes YAML from a running Podman pod.
Beginner
Situation read โ Bridge from local dev to cluster.
What I'd do โ
podman pod create --name shop -p 8080:80
podman run -d --pod shop --name web nginx:1.27
podman generate kube shop > shop.yaml
podman kube play shop.yamlWhy โ Podman understands pods natively.
Interview tip โ Treat generated YAML as a starting point to edit.
Q163 What are the storage drivers and which would you use?
Intermediate
Situation read โ Know the options.
What I'd do โ overlay2 is the default and recommended (ext4 or xfs with d_type); newer Docker uses the containerd image store with the overlayfs snapshotter; btrfs/zfs when the host already uses them for snapshots; devicemapper and aufs are removed/deprecated. Check docker info -f '{{.Driver}}'.
Why โ overlay2 has the best performance and kernel support.
Interview tip โ Moving /var/lib/docker requires data-root in daemon.json.
Q164 Use buildah or Kaniko to build images without a Docker daemon in CI.
Intermediate
Situation read โ Cannot expose the Docker socket in shared runners.
What I'd do โ Kaniko runs in a pod without privileges:
/kaniko/executor --context $CI_PROJECT_DIR --dockerfile Dockerfile \
--destination reg.example.com/app:$CI_COMMIT_SHA --cache=trueOr buildah bud rootless, or BuildKit rootless (rootlesskit buildkitd). Note that Kaniko's upstream is archived; forks and BuildKit are common alternatives now.
Why โ No privileged daemon needed.
Interview tip โ Say you verify maintenance status of tools before adopting.
Q165 Run Docker-in-Docker safely for CI.
Advanced
Situation read โ Jobs need to run docker build and docker run.
What I'd do โ Prefer socket-less builds (BuildKit, Kaniko). If DinD is needed, use docker:dind-rootless or Sysbox runtime so inner Docker does not require --privileged, give each job its own ephemeral daemon, and use TLS (DOCKER_TLS_CERTDIR=/certs).
Why โ Privileged DinD is host-root equivalent.
Interview tip โ Socket mounting shares the host daemon; DinD isolates it but is privileged.
Q166 How are containers isolated at kernel level?
Beginner
Situation read โ Fundamental concept.
What I'd do โ Namespaces (pid, net, mnt, uts, ipc, user, cgroup) restrict what a process sees; cgroups limit what it can use; capabilities, seccomp and LSMs (AppArmor/SELinux) restrict what it can do.
lsns -p $(docker inspect -f '{{.State.Pid}}' web)Why โ Containers are regular processes with restricted views, not VMs.
Interview tip โ Shared kernel is the key difference from VMs.
Q167 Check how a container's cgroup limits look on the host.
Intermediate
Situation read โ Verify limits are really applied.
What I'd do โ
CID=$(docker inspect -f '{{.Id}}' web)
cat /sys/fs/cgroup/system.slice/docker-$CID.scope/memory.max
cat /sys/fs/cgroup/system.slice/docker-$CID.scope/cpu.max(systemd cgroup driver, cgroup v2 paths).
Why โ Proves the engine translated flags into kernel limits.
Interview tip โ Use systemd-cgls or systemd-cgtop for a live view.
Q168 Pull images through a local cache for a remote office.
Intermediate
Situation read โ Slow WAN, repeated pulls.
What I'd do โ Run a registry in pull-through mode:
proxy:
remoteurl: https://registry-1.docker.ioConfigure clients: {"registry-mirrors": ["https://mirror.office.example.com"]}. Or Harbor proxy-cache projects.
Why โ Layers download once per site.
Interview tip โ registry-mirrors applies to Docker Hub only.
Q169 Verify what capabilities a running container has and why it matters.
Intermediate
Situation read โ Audit privileges.
What I'd do โ
docker inspect -f '{{.HostConfig.CapAdd}} {{.HostConfig.CapDrop}}' c
docker exec c grep Cap /proc/1/status
capsh --decode=00000000a80425fbWhy โ Default set includes NET_RAW, CHOWN, SETUID etc.; drop what the app doesn't need.
Interview tip โ NET_RAW allows ARP spoofing in shared bridges.
Q170 Migrate Compose files to Kubernetes.
Intermediate
Situation read โ Moving up from a single host.
What I'd do โ Use kompose convert as a first draft, then hand-edit: replace depends_on with readiness probes, volumes with PVCs, ports with Services/Ingress, secrets with Secret objects, resources with requests/limits. Package with Helm or Kustomize.
Why โ Tools translate structure, not operational semantics.
Interview tip โ Check that images can run as non-root; Pod Security rules are stricter.
Q171 Why might docker build and podman build give different results?
Advanced
docker build and podman build give different results?Situation read โ Builders are not identical.
What I'd do โ Differences: Docker uses BuildKit (cache/secret mounts, # syntax frontends), Podman uses Buildah (supports most BuildKit mount types but not every feature); default image format (Podman builds OCI, may drop HEALTHCHECK unless --format docker), rootless UID mapping affecting file ownership, and short-name resolution via registries.conf.
Why โ HEALTHCHECK isn't part of the OCI image config.
Interview tip โ Use fully qualified image names with Podman.
Q172 Configure registry mirrors and insecure registries for containerd.
Intermediate
Situation read โ Private registry with self-signed TLS.
What I'd do โ Preferred: trust the CA. With containerd use config_path and /etc/containerd/certs.d/reg.example.com/hosts.toml:
server = "https://reg.example.com"
[host."https://reg.example.com"]
ca = "/etc/containerd/certs.d/reg.example.com/ca.crt"For Docker: place the CA in /etc/docker/certs.d/reg.example.com/ca.crt, no restart needed.
Why โ Avoids disabling TLS verification.
Interview tip โ insecure-registries is a last resort.
Q173 Explain how image layers are stored and shared on a node.
Intermediate
Situation read โ Understand deduplication.
What I'd do โ Each layer is unpacked once into a snapshot under /var/lib/docker/overlay2/<id> (or containerd snapshotter). Containers stack read-only lower dirs with one writable upper dir via overlayfs. Images sharing a base reuse the same lower layers.
docker inspect -f '{{json .GraphDriver.Data}}' web | jqWhy โ Saves disk and speeds up pulls/starts.
Interview tip โ docker system df double-counts shared layers in "reclaimable".
Q174 Use Podman to run a pod-like stack without root and expose it.
Intermediate
Situation read โ Developer laptop or small server.
What I'd do โ
podman network create appnet
podman run -d --name db --network appnet -v pgdata:/var/lib/postgresql/data postgres:17
podman run -d --name api --network appnet -p 8080:8080 localhost/api:1Use netavark/aardvark-dns for name resolution and podman volume for storage.
Why โ Works rootless with slirp4netns or pasta networking.
Interview tip โ Rootless networking is slower; mention pasta as the newer default.
Q175 Checkpoint and restore a container. When is it useful?
Advanced
Situation read โ Fast warm start or forensic capture.
What I'd do โ Podman: podman container checkpoint web -e /tmp/web.tar.gz then podman container restore -i /tmp/web.tar.gz. Docker: experimental docker checkpoint create. Both rely on CRIU, which has limits with network connections, GPUs and some kernel features.
Why โ Useful for slow-starting apps and forensic snapshots, not a replacement for HA.
Interview tip โ Kubernetes forensic checkpointing is an alpha/beta feature in kubelet.
CI/CD and production rollouts
๐ฅ Learn this hands-on with DevOps Shack โ YouTube @devopsshack ยท Hindi @shackverse ยท Courses at devopsshack.com
Q176 Design a GitHub Actions workflow that builds, scans and pushes an image.
Intermediate
Situation read โ Standard CI for containers.
What I'd do โ
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with: { registry: ghcr.io, username: ${{ github.actor }}, password: ${{ secrets.GITHUB_TOKEN }} }
- uses: docker/build-push-action@v6
with:
push: false
load: true
tags: ghcr.io/acme/app:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- run: trivy image --exit-code 1 --severity CRITICAL ghcr.io/acme/app:${{ github.sha }}
- run: docker push ghcr.io/acme/app:${{ github.sha }}Why โ Scan before push so bad images never reach the registry.
Interview tip โ Pin actions by SHA in sensitive repos.
Q177 Zero-downtime deploy on a single Docker host.
Advanced
Situation read โ No orchestrator available.
What I'd do โ Blue/green with a reverse proxy: start the new version as api-green, wait for healthy, switch the proxy upstream (Traefik label or nginx include + nginx -s reload), drain and stop api-blue. Tools such as docker rollout plugin or Compose + Traefik automate this.
Why โ Proxy switch is atomic; old containers finish in-flight requests.
Interview tip โ Also mention DB migrations must be backward compatible.
Q178 Deploy via GitOps with image digests.
Intermediate
Situation read โ Want auditable deployments.
What I'd do โ CI builds and pushes app:$SHA, then updates the deployment repo (Kustomize images: or Helm values) to the digest via PR. Argo CD or Flux syncs. Image Updater/Flux image automation can also do it.
Why โ Git history is the deployment history; rollback is a revert.
Interview tip โ Separate app repo from environment repo.
Q179 Canary a new image on a Swarm service.
Advanced
Situation read โ Gradual rollout.
What I'd do โ
docker service update --image reg/app:1.9.0 \
--update-parallelism 1 --update-delay 30s \
--update-failure-action rollback --update-monitor 60s app
docker service rollback appWhy โ Rolls task by task and rolls back automatically on failed health.
Interview tip โ For weighted traffic splitting you need a service mesh or Traefik weighted services.
Q180 Docker build is flaky in CI due to network errors on package installs.
Intermediate
Situation read โ External mirrors fail intermittently.
What I'd do โ Use internal package proxies (Artifactory/Nexus/Athens), add retries (pip --retries 5, apt -o Acquire::Retries=3), vendor dependencies for critical paths, and use cache mounts.
Why โ Reduces external dependency on the critical path.
Interview tip โ Flaky builds are an availability problem for the whole team.
Q181 Run database migrations in the deploy flow of containerized apps.
Intermediate
Situation read โ Old and new code run concurrently during rollout.
What I'd do โ Run migrations as a one-off job (docker compose run --rm migrate, a Kubernetes Job or init step) before switching traffic, using expand/contract: add columns first, deploy, then drop old ones later. Take a backup before destructive changes.
Why โ Backward-compatible schemas enable rollback.
Interview tip โ Never run migrations in every replica's entrypoint.
Q182 How do you keep dev, CI and prod consistent?
Beginner
Situation read โ "Works on my machine."
What I'd do โ Same Dockerfile everywhere, same image promoted across environments, config via env, dev containers/Compose mirroring prod dependencies versions (postgres:17, not "whatever is on the laptop").
Why โ Differences in environment are the root of most bugs.
Interview tip โ Build once, promote by digest.
Q183 Estimate and reduce deployment time for a 1.5 GB image across 50 nodes.
Advanced
Situation read โ Registry egress and pull time dominate.
What I'd do โ Shrink the image, order layers so base layers are shared, use a regional mirror or pull-through cache, pre-pull (DaemonSet or docker pull in bake), enable lazy pulling (stargz/SOCI, Nydus) and parallel layer downloads (max-concurrent-downloads). Use zstd compression for faster extraction.
Why โ Pull + unpack time often exceeds app start.
Interview tip โ Measure first: pull time vs extract vs start.
Q184 Handle environment-specific build args without separate images.
Beginner
Situation read โ Front-end apps embedding API URLs at build time.
What I'd do โ Use runtime config: serve /config.js generated at container start from env vars via entrypoint (envsubst), so one image runs everywhere.
Why โ Avoids per-environment builds.
Interview tip โ Build-time injection is only acceptable for non-env-specific values.
Q185 Test Dockerfile changes safely before merging.
Beginner
Situation read โ A broken Dockerfile blocks everyone.
What I'd do โ PR pipeline: hadolint Dockerfile, docker buildx build --check, build for all target platforms without pushing, run container structure tests (container-structure-test) or a smoke test hitting /healthz.
Why โ Catches issues early.
Interview tip โ docker build --check validates against Dockerfile build checks.
Q186 Rollback strategy when a new image passes health checks but errors under load.
Advanced
Situation read โ Health checks are shallow.
What I'd do โ Monitor error rate and latency SLOs during rollout, auto-rollback via progressive delivery (Argo Rollouts, Flagger) or Swarm --update-monitor, keep the previous digest in the deployment record, and use feature flags to separate deploy from release.
Why โ Behavioural regressions need metrics-based gates.
Interview tip โ Describe rollout gates on SLIs.
Q187 How do you manage Docker daemon configuration across a fleet?
Intermediate
Situation read โ Consistency of daemon.json.
What I'd do โ Manage with Ansible/Terraform/cloud-init, version in git, validate with dockerd --validate --config-file /etc/docker/daemon.json, and roll changes in batches. Many settings need a restart; use live-restore to reduce impact.
Why โ Drift in log options or address pools causes outages.
Interview tip โ Test config before restart; a bad JSON stops dockerd.
Q188 Docker Hub is down during a production deploy.
Intermediate
Situation read โ External dependency on the critical path.
What I'd do โ Deploy from our own registry (images already mirrored), check nodes have cached layers, and for the future mirror all base images and use pull-through caches.
Why โ Production deployment should not depend on third parties.
Interview tip โ Reference the 2021-era rate limit and outages as motivation.
Q189 Cut CI costs for container builds.
Intermediate
Situation read โ Heavy builds on every push.
What I'd do โ Path filters to build only changed services, remote caches, smaller images, multi-stage targets, avoid multi-arch on every PR (build arm64 only on main/tags), and use larger fewer runners with persistent BuildKit.
Why โ Time and compute are proportional to rebuilt layers.
Interview tip โ Track build minutes per service.
Q190 A new junior pushed an image with a secret. Incident steps.
Intermediate
Situation read โ Secret exposure incident.
What I'd do โ
- Revoke and rotate the secret immediately.
- Identify exposure: pull logs, who pulled the tag.
- Delete image tags and untagged manifests, run registry GC.
- Add
.dockerignoreand secret scanning. - Write a blameless postmortem.
Why โ Rotation is the only real remediation.
Interview tip โ Time-to-rotate matters more than time-to-delete.
Q191 Manage multiple environments with one Compose repo.
Beginner
Situation read โ dev/staging/prod variants.
What I'd do โ compose.yaml base + compose.<env>.yaml overrides, --env-file .env.<env>, and COMPOSE_PROJECT_NAME per environment so networks and volumes are separated. Validate with docker compose config.
Why โ Project names isolate resources on the same host.
Interview tip โ Use profiles for optional services (e.g., debug).
Q192 Make image builds faster for a monorepo with 20 services.
Advanced
Situation read โ Shared context makes everything rebuild.
What I'd do โ Use docker buildx bake with a docker-bake.hcl defining targets and shared base, per-service .dockerignore (via Dockerfile.dockerignore), COPY only the service path plus shared libs, remote cache and --set *.cache-to. Detect changed services in CI with git diff.
Why โ Bake builds targets in parallel with shared cache.
Interview tip โ Context size matters: use named contexts to limit it.
Q193 Patch a critical OpenSSL CVE across 80 images.
Advanced
Situation read โ Fleet-wide urgent patch.
What I'd do โ Query the SBOM index to find affected images, rebuild the golden base first, then trigger downstream rebuilds (Renovate/Dependabot or a pipeline fan-out), scan, sign and roll out by priority (internet-facing first). Track completion in a dashboard.
Why โ Central bases and inventory make this a day, not a month.
Interview tip โ Mention measuring blast radius with SBOMs.
Q194 Where do you run containers for a small team: Compose on a VM, ECS, or Kubernetes?
Intermediate
Situation read โ Choose by scale and team skill.
What I'd do โ A few services and small team: Compose on a VM (or ECS Fargate/Cloud Run if on cloud) with backups and monitoring. Kubernetes when you need autoscaling, multi-team multi-tenant, rich rollout strategies, or many services. Avoid operating Kubernetes without capacity to maintain it.
Why โ Operational cost should match need.
Interview tip โ Defend the choice with requirements, not trends.
Q195 Run scheduled jobs in containers.
Beginner
Situation read โ Periodic tasks like cleanup.
What I'd do โ Use the host's cron/systemd timer calling docker run --rm job:1.0, or a scheduler container, or Kubernetes CronJob. Avoid running crond inside app containers.
Why โ Jobs get their own limits, logs and exit codes.
Interview tip โ Make jobs idempotent.
Q196 Reduce attack surface of CI build environment itself.
Advanced
Situation read โ Builders have registry credentials.
What I'd do โ Ephemeral runners, short-lived OIDC credentials to the registry (no static keys), least-privilege push scopes per repo, no socket sharing, network egress allow-lists, and signed provenance for builds.
Why โ A compromised builder can push poisoned images.
Interview tip โ OIDC federation removes stored registry passwords.
Q197 How do you version and publish a base image used by other teams?
Intermediate
Situation read โ Internal platform responsibility.
What I'd do โ Publish immutable dated tags (2026.11.09) and moving tags (3.12), changelog, SBOM and signatures, a deprecation policy, and automated PRs to consumers. Monitor adoption.
Why โ Consumers choose stability or freshness knowingly.
Interview tip โ Treat internal images as products.
Q198 Containerize a legacy app that writes config on startup and expects root.
Advanced
Situation read โ Not cloud-native.
What I'd do โ Wrap with an entrypoint that templates config from env into a writable dir, run as non-root with chown on needed dirs at build time, mount state on a volume, send logs to stdout, and add a health script. If root is unavoidable, drop capabilities, use userns/rootless and read-only mounts.
Why โ Incremental hardening beats rewriting.
Interview tip โ Document the exceptions and set a remediation plan.
Q199 Choose between docker compose watch, bind mounts and rebuilds for developer inner loop.
Intermediate
docker compose watch, bind mounts and rebuilds for developer inner loop.Situation read โ Fast feedback matters.
What I'd do โ develop.watch with sync for interpreted code, sync+restart for config changes, rebuild for dependency manifest changes:
develop:
watch:
- { action: sync, path: ./src, target: /app/src }
- { action: rebuild, path: package.json }Why โ Avoids bind-mount perf and ownership problems while keeping speed.
Interview tip โ Run with docker compose up --watch.
Q200 Walk me through taking a container app from laptop to production at a high level.
Beginner
Situation read โ Open-ended end-to-end question.
What I'd do โ
- Write a Dockerfile (multi-stage, non-root, pinned base, healthcheck).
- Compose for local dependencies.
- CI: lint, build, test, scan, SBOM, sign, push by SHA.
- Promote the same digest through environments via GitOps.
- Run with limits, probes, centralized logs and metrics.
- Plan rollbacks, backups and patch cadence.
Why โ Every step reduces a class of production failures.
Interview tip โ Structure the answer as build, ship, run.