node_modules bin obj .git Why it mattersSmaller build context = faster builds, fewer leaks.
Daily micro-tips for C#, SQL, performance, and scalable backend engineering.
node_modules bin obj .git Why it mattersSmaller build context = faster builds, fewer leaks.
FROM node:18 AS build RUN npm run build FROM nginx:alpine COPY –from=build /app/dist /usr/share/nginx/html Why it mattersRemoves build junk → secure & tiny images.
The problem is usually the base image. # ❌ Heavy FROM mcr.microsoft.com/dotnet/sdk:8.0 # ✅ Lightweight FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine Why this mattersSmaller images = faster pull, faster start, lower memory pressure.
Most people say multi-stage builds are for smaller images.Wrong. They’re about attack surface. FROM mcr.microsoft.com/dotnet/sdk AS build WORKDIR /src COPY . . RUN dotnet publish -c Release -o /app FROM mcr.microsoft.com/dotnet/aspnet WORKDIR /app COPY –from=build /app . Why it matters: No SDK in production Fewer CVEs Faster cold starts Smaller image is just a side […]
Most “random” container crashes are not random at all — they’re OOM kills. By default, Docker containers have no memory awareness unless you explicitly define it. services: api: image: my-api deploy: resources: limits: memory: 512M Why this mattersWithout limits, the container can consume host memory freely.Linux kernel steps in → kills your container → zero […]
One line edit → full rebuild. Why it happensCOPY order invalidates cache. Why it mattersCI/CD pipelines slow down. Vital fix COPY *.csproj . RUN dotnet restore COPY . .
The Mystery: Your Docker image builds perfectly on Linux or CI/CD, but the moment you or a teammate tries to run it on Windows, the container exits instantly with a cryptic exec format error or standard_init_linux.go:211: exec user process caused “no such file or directory”. The Culprit: It’s not your code; it’s the invisible characters […]
Same app, bigger image. Why it happensLayer caching invalidated by COPY order. Why it mattersSlower builds, higher registry costs. Smart fixCopy dependency files first, source later.
Same image, different result. WhyMissing environment variables. TipExplicitly define ENV values in Dockerfile.
Same app, bigger image. WhyUnoptimized layer ordering. TipPlace rarely changed steps first in Dockerfile.
Local success, CI failure. WhyImplicit local file system assumptions. TipAlways build containers using clean contexts.
Builds succeed, debugging is painful. WhySingle-stage images mix runtime and build tools. TipSeparate build and runtime layers.
Same Dockerfile, slower builds. WhyLayer cache invalidation caused by small file changes. Tip Copy dependency files before source code.
Even after cleanup. WhyDangling layers and build cache accumulate. Maintenance Tip Schedule periodic build cache pruning.
First run is fast, restart is slow. WhyVolume mounts re-initialize filesystem state. Fix Avoid mounting large directories unless necessary.
Same app, bigger image. WhyLayer cache accumulates unused artifacts. Fix Use multi-stage builds and remove build-time dependencies.
Exit code 0 but container dies. WhyMain process exits immediately. FixEnsure a blocking foreground process.
Every build starts from scratch. WhyBuild context changes invalidate cache layers. FixUse .dockerignore aggressively.
Local works perfectly. WhyENV values differ from ARG during build vs runtime. FixUse ENV for runtime, ARG only for build.
Same image, different result. WhyCI runs on a different CPU architecture. FixBuild multi-arch images explicitly.
Builds take forever. WhyDependencies and source copied in wrong order. Fix COPY *.csproj ./ RUN dotnet restore COPY . .
First run ok, second run broken. WhyStateful data written inside container layer. Fix Always mount volumes for persistent data.
You changed one line… everything rebuilt. Why it happensCOPY instructions invalidate layers. FixCopy dependency files first, source files last.
OverlayFS slows heavy file IO. Fix Use volumes for write-heavy paths.
latest changes silently. ❌ Risk Unexpected production behavior. ✅ Fix Pin exact image versions.
Bad order: COPY . . RUN npm install ✅ Fix Copy manifests first, install, then source.