Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: Docker

Docker

Docker: Use Compose Profiles to Start Only Needed Services

- 17.02.26 - ErcanOPAK comment on Docker: Use Compose Profiles to Start Only Needed Services

Running all services (database, cache, queue, monitoring) every time is slow. Profiles start only what you need. docker-compose.yml: services: app: build: . ports: – “3000:3000” db: image: postgres profiles: [“dev”, “test”] redis: image: redis profiles: [“dev”] monitoring: image: grafana profiles: [“monitoring”] mailhog: image: mailhog/mailhog profiles: [“dev”] Start Different Profiles: # Just the app (no extras) […]

Read More
Docker

Docker: Use ARG for Build-Time Variables and ENV for Runtime

- 16.02.26 - ErcanOPAK comment on Docker: Use ARG for Build-Time Variables and ENV for Runtime

Confusing ARG and ENV causes build issues. Know when to use each. ARG – Build-Time Only: FROM node:18 ARG NODE_ENV=production ARG API_URL=https://api.example.com RUN echo “Building for ${NODE_ENV}” RUN npm install –${NODE_ENV} # ARG values NOT available at runtime! Build with ARG: docker build –build-arg NODE_ENV=development -t myapp . ENV – Runtime Variables: FROM node:18 ENV […]

Read More
Docker

Docker: Use Docker Init to Generate Dockerfiles Automatically

- 15.02.26 - ErcanOPAK comment on Docker: Use Docker Init to Generate Dockerfiles Automatically

Writing Dockerfiles from scratch is error-prone. Docker init analyzes your project and generates optimized Dockerfile. Run in Project Directory: docker init # Detects project type (Node.js, Python, Go, etc.) # Asks questions about your app # Generates: # – Dockerfile # – .dockerignore # – docker-compose.yml Example Output for Node.js: Creates multi-stage build, sets up […]

Read More
Docker

Docker: Use Multi-Stage Builds to Reduce Final Image Size by 90%

- 15.02.26 - ErcanOPAK comment on Docker: Use Multi-Stage Builds to Reduce Final Image Size by 90%

Including build tools in final image wastes space. Multi-stage builds separate build and runtime. Single-Stage (Large): FROM node:18 WORKDIR /app COPY . . RUN npm install # Includes dev dependencies RUN npm run build CMD [“node”, “dist/server.js”] # Result: 1.2 GB (includes npm, build tools) Multi-Stage (Small): # Stage 1: Build FROM node:18 AS builder […]

Read More
Docker

Docker: UseHealthCheck to Auto-Restart Unhealthy Containers

- 14.02.26 - ErcanOPAK comment on Docker: UseHealthCheck to Auto-Restart Unhealthy Containers

Container running but app inside crashed? Add HEALTHCHECK to auto-detect and restart failed containers. Add to Dockerfile: FROM node:18 WORKDIR /app COPY . . # Check if app responds on port 3000 HEALTHCHECK –interval=30s –timeout=3s –retries=3 \ CMD curl -f http://localhost:3000/health || exit 1 CMD [“node”, “server.js”] What Happens: Every 30 seconds, Docker runs health […]

Read More
Docker

Docker: Use .dockerignore to Speed Up Builds and Reduce Image Size

- 13.02.26 - ErcanOPAK comment on Docker: Use .dockerignore to Speed Up Builds and Reduce Image Size

Copying node_modules, .git, and cache files into images wastes time and space. Exclude them with .dockerignore. Create .dockerignore in project root: node_modules npm-debug.log .git .gitignore *.md .env .vscode .idea **/*.log **/dist **/bin **/obj Impact: Without .dockerignore: – Build time: 45 seconds – Image size: 850 MB (includes node_modules) With .dockerignore: – Build time: 8 seconds […]

Read More
Docker

Docker: Use docker compose watch to Auto-Rebuild on File Changes

- 13.02.26 - ErcanOPAK comment on Docker: Use docker compose watch to Auto-Rebuild on File Changes

Manually rebuilding Docker containers after every code change? Docker Compose watch auto-rebuilds on file save. Add to docker-compose.yml: services: web: build: . develop: watch: – path: ./src action: rebuild Start with watch: docker compose watch Edit src/ files → Docker auto-rebuilds container. No manual restart needed! Actions: rebuild (full rebuild), sync (copy files), sync+restart (copy […]

Read More
Docker

Docker Compose: Launch Full Stack Apps with One Command (Node + Redis + Postgres)

- 05.02.26 - ErcanOPAK comment on Docker Compose: Launch Full Stack Apps with One Command (Node + Redis + Postgres)

Manually starting 5 different services for development? Docker Compose defines and runs multi-container apps. # docker-compose.yml version: ‘3.8’ services: # Node.js API api: build: ./api ports: – “3000:3000” environment: – NODE_ENV=development – REDIS_URL=redis://redis:6379 – DATABASE_URL=postgresql://user:pass@db:5432/mydb volumes: – ./api:/app – /app/node_modules depends_on: – redis – db command: npm run dev # React Frontend frontend: build: ./frontend […]

Read More
Docker

Docker: Clean Up Disk Space by Removing Unused Images and Containers

- 03.02.26 - ErcanOPAK comment on Docker: Clean Up Disk Space by Removing Unused Images and Containers

Docker eating 50GB of disk space? Old images, stopped containers, and dangling volumes pile up fast. One command reclaims it all. Check Current Disk Usage: docker system df # Output: TYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 47 12 28.5GB 18.2GB (63%) Containers 89 5 10.2GB 9.8GB (96%) Local Volumes 23 8 2.3GB 1.1GB (47%) Build […]

Read More
Docker

Reduce Docker Image Sizes by 10x with Multi-Stage Builds

- 01.02.26 | 01.02.26 - ErcanOPAK comment on Reduce Docker Image Sizes by 10x with Multi-Stage Builds

Your Docker image is 1.2GB when it should be 120MB? Multi-stage builds eliminate build dependencies from your final image. The Problem – Single Stage Build: FROM node:18 WORKDIR /app COPY package*.json ./ RUN npm install # Installs 300MB of dev dependencies COPY . . RUN npm run build # Creates 10MB production build CMD [“node”, […]

Read More
Docker

Why Your Docker Image Is Slow Even Though It’s “Small”

- 31.01.26 - ErcanOPAK comment on Why Your Docker Image Is Slow Even Though It’s “Small”

Image size ≠ image performance. Hidden cause Layer invalidation. Most Dockerfiles are written like this: COPY . . RUN npm install Every small file change invalidates the cache. Correct approach COPY package.json package-lock.json ./ RUN npm install COPY . . Cause → Effect Stable dependency layers Faster rebuilds Lower CI/CD costs This is why two […]

Read More
Docker

Why Docker Containers Randomly Slow Down After Days (Even With Low Traffic)

- 30.01.26 - ErcanOPAK comment on Why Docker Containers Randomly Slow Down After Days (Even With Low Traffic)

If a container runs for days, performance can degrade without any load increase. What actually happens Linux page cache grows but isn’t reclaimed fast enough Log files inside containers expand silently OverlayFS layers fragment over time Golden principle Containers are ephemeral by design, not meant to be immortal. Fix Externalize logs Restart containers on a […]

Read More
Docker

Why Docker Containers Get Slower Over Time (Even Without Traffic)

- 29.01.26 - ErcanOPAK comment on Why Docker Containers Get Slower Over Time (Even Without Traffic)

A container runs fine at first… then slowly degrades. No spikes. No crashes. Just silent slowness. Root cause Layered filesystem (OverlayFS) grows Log files inside containers never rotate Memory fragmentation inside long-lived containers Golden rule Containers are not VMs. They are disposable. Fix Never log to disk inside containers Use external logging drivers Restart containers […]

Read More
Docker

Multi-Stage Builds = Smaller Images

- 28.01.26 - ErcanOPAK comment on Multi-Stage Builds = Smaller Images

FROM mcr.microsoft.com/dotnet/sdk AS build FROM mcr.microsoft.com/dotnet/aspnet Why it mattersFinal image contains only runtime → faster deploys, fewer vulnerabilities.

Read More
Docker

Use .dockerignore Like .gitignore

- 27.01.26 - ErcanOPAK comment on Use .dockerignore Like .gitignore

node_modules bin obj .git Why it mattersSmaller build context = faster builds, fewer leaks.

Read More
Docker

Multi-Stage Builds = Smaller Images, Faster Deploys

- 26.01.26 - ErcanOPAK comment on Multi-Stage Builds = Smaller Images, Faster Deploys

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.

Read More
Docker

Why Your Containers Are Slow Even on Powerful Machines

- 25.01.26 - ErcanOPAK comment on Why Your Containers Are Slow Even on Powerful Machines

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.

Read More
Docker

Why Multi-Stage Builds Are About Security, Not Size

- 24.01.26 - ErcanOPAK comment on Why Multi-Stage Builds Are About Security, Not Size

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 […]

Read More
Docker

The Hidden Reason Your Containers Randomly Die in Production

- 24.01.26 - ErcanOPAK comment on The Hidden Reason Your Containers Randomly Die in Production

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 […]

Read More
Docker

Docker Builds Are Slow Even with Small Changes

- 23.01.26 - ErcanOPAK comment on Docker Builds Are Slow Even with Small Changes

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 . .  

Read More
Docker

Docker Containers Randomly Exit on Windows

- 22.01.26 | 15.02.26 - ErcanOPAK comment on Docker Containers Randomly Exit on Windows

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 […]

Read More
Docker

Docker Images Grow Bigger Every Build

- 21.01.26 - ErcanOPAK comment on Docker Images Grow Bigger Every Build

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.

Read More
Docker

Docker Containers Work Locally but Fail in CI

- 18.01.26 - ErcanOPAK comment on Docker Containers Work Locally but Fail in CI

Same image, different result. WhyMissing environment variables. TipExplicitly define ENV values in Dockerfile.

Read More
Docker

Docker Images Suddenly Grow Huge

- 16.01.26 - ErcanOPAK comment on Docker Images Suddenly Grow Huge

Same app, bigger image. WhyUnoptimized layer ordering. TipPlace rarely changed steps first in Dockerfile.

Read More
Docker

Docker Containers Work Locally but Fail in CI

- 15.01.26 - ErcanOPAK comment on Docker Containers Work Locally but Fail in CI

Local success, CI failure. WhyImplicit local file system assumptions. TipAlways build containers using clean contexts.

Read More
Docker

Docker Images Work but Are Hard to Maintain

- 14.01.26 - ErcanOPAK comment on Docker Images Work but Are Hard to Maintain

Builds succeed, debugging is painful. WhySingle-stage images mix runtime and build tools. TipSeparate build and runtime layers.

Read More
Docker

Docker Builds Get Slower Over Time

- 13.01.26 - ErcanOPAK comment on Docker Builds Get Slower Over Time

Same Dockerfile, slower builds. WhyLayer cache invalidation caused by small file changes. Tip Copy dependency files before source code.

Read More
Docker

Docker Containers Consume More Disk Over Time

- 12.01.26 - ErcanOPAK comment on Docker Containers Consume More Disk Over Time

Even after cleanup. WhyDangling layers and build cache accumulate. Maintenance Tip Schedule periodic build cache pruning.

Read More
Docker

Docker Containers Start Slowly on Restart

- 11.01.26 - ErcanOPAK comment on Docker Containers Start Slowly on Restart

First run is fast, restart is slow. WhyVolume mounts re-initialize filesystem state. Fix Avoid mounting large directories unless necessary.

Read More
Docker

Docker Images Grow Over Time Without Reason

- 07.01.26 - ErcanOPAK comment on Docker Images Grow Over Time Without Reason

Same app, bigger image. WhyLayer cache accumulates unused artifacts. Fix Use multi-stage builds and remove build-time dependencies.

Read More
Page 1 of 2
1 2 Next »

Posts navigation

Older posts
February 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
232425262728  
« Jan    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (832)
  • Get the First and Last Word from a String or Sentence in SQL (826)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (716)
  • Add Constraint to SQL Table to ensure email contains @ (574)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (553)
  • Average of all values in a column that are not zero in SQL (520)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (474)
  • Find numbers with more than two decimal places in SQL (436)

Recent Posts

  • C#: Use MemoryPack for 10x Faster Serialization than JSON
  • C#: Use params ReadOnlySpan for Allocation-Free Variable Arguments
  • C#: Use ObjectPool for Reusing Expensive Objects
  • C#: Use Lazy for Expensive Object Initialization
  • SQL: Use STRING_AGG to Concatenate Rows into Comma-Separated List
  • SQL: Use Filtered Indexes to Index Only Subset of Rows
  • .NET Core: Use Result Pattern to Avoid Exceptions for Expected Errors
  • .NET Core: Use IOptions Pattern for Strongly-Typed Configuration
  • Git: Use .gitattributes to Handle Line Endings Across OS
  • Git: Use git notes to Add Comments to Commits Without Changing History

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (935)
  • How to add default value for Entity Framework migrations for DateTime and Bool (832)
  • Get the First and Last Word from a String or Sentence in SQL (826)
  • How to select distinct rows in a datatable in C# (799)
  • How to make theater mode the default for Youtube (716)

Recent Posts

  • C#: Use MemoryPack for 10x Faster Serialization than JSON
  • C#: Use params ReadOnlySpan for Allocation-Free Variable Arguments
  • C#: Use ObjectPool for Reusing Expensive Objects
  • C#: Use Lazy for Expensive Object Initialization
  • SQL: Use STRING_AGG to Concatenate Rows into Comma-Separated List

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com