Preparing for a DevOps interview that covers Docker? These questions come up again and again - here are strong, concrete answers.
Q: What is Docker and why use it?
Docker builds, ships and runs applications inside containers - isolated processes that bundle the code, runtime and libraries so 'works on my machine' stops being a problem.
- Reproducible builds: the same image runs identically on a laptop, CI and production
- Fast, isolated environments without the overhead of full virtual machines
- A universal packaging format that every orchestrator and cloud understands
Q: What are the best practices you follow?
- Pin base image tags (or digests) instead of :latest for reproducibility
- Order layers from least- to most-frequently changed to maximize cache hits
- Use multi-stage builds to keep runtime images tiny and attack surface small
- Add a HEALTHCHECK and run as a non-root user
Q: What mistakes have you seen?
- Running as root inside the container - always add a non-root USER
- Fat images from a single-stage build; use multi-stage and slim/alpine bases
- Baking secrets into layers with COPY or ENV - they stay in the image history
- No .dockerignore, so node_modules and .git bloat the build context
Q: Show a basic configuration
A small, cache-friendly multi-stage Dockerfile for a Node service.
# syntax=docker/dockerfile:1
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:20-alpine AS run
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/dist ./dist
COPY --from=build /app/node_modules ./node_modules
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]Want senior help putting Docker to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.