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
AI

The AI Prompt That Reviews a Dockerfile for Avoidable Image Bloat

- 03.10.26 - ErcanOPAK

🤖 The AI Prompt That Finds Exactly Why Your Image Is Bigger Than It Needs to Be

A Docker image that’s grown to several times the size it should reasonably be rarely has one obvious cause – it’s usually a handful of small, individually-reasonable-looking decisions (a base image that’s heavier than necessary, build tools left in the final layer instead of being discarded after a multi-stage build, a package manager’s cache never cleaned up, a COPY instruction that pulls in far more of the build context than the image actually needs) that add up quietly over the Dockerfile’s lifetime. This prompt asks an AI assistant to walk through a Dockerfile line by line looking specifically for that category of avoidable size.

📋 The Prompt

Here's our Dockerfile (and, if relevant, the .dockerignore file next to
it). Walk through it and identify specific, concrete opportunities to
reduce the final image size, including:

1. Whether the base image could reasonably be a smaller variant (an
   alpine or slim tag, or a distroless image) given what the
   application actually needs at runtime
2. Any build-time-only tools, compilers, or dependencies that end up
   in the final image layer instead of being isolated to an earlier
   stage of a multi-stage build and discarded
3. Package manager cache directories or temporary files that get
   created during a RUN instruction but never cleaned up in that
   same instruction (which matters because of how Docker layers work)
4. Whether .dockerignore is missing entries that would stop
   unnecessary files (version control metadata, local dependency
   folders, test fixtures) from being copied into the build context
   at all

For each finding, estimate roughly how much size impact it likely has
relative to the others, so the biggest wins are obvious.

Dockerfile:
[PASTE THE DOCKERFILE AND .dockerignore HERE]

✅ Why This Prompt Works

  • Asking for a relative size-impact estimate per finding, even a rough one, turns a list of ‘things that could be better’ into something that can actually be prioritized – switching a base image is usually the single biggest win, and knowing that up front saves time compared to fixing a dozen small things first.
  • Specifically checking whether a RUN instruction cleans up in the same instruction it creates cache or temp files in targets a subtle but very common mistake – because Docker layers are immutable once created, a cleanup command in a later, separate RUN instruction doesn’t actually shrink the image, only one combined in the same instruction does.
  • Reviewing .dockerignore alongside the Dockerfile catches a frequently-overlooked cause of bloat that isn’t even visible in the Dockerfile itself – a large, unnecessary build context gets copied into intermediate layers via COPY instructions regardless of how clean the Dockerfile’s own instructions look.

⚠️ Where to Draw the Line

  • Size estimates here are reasoning from general knowledge of how base images, package managers, and layer caching behave, not from actually building and measuring the image – running docker build with –progress=plain and comparing layer sizes directly afterward confirms which findings actually mattered most.
  • A smaller base image isn’t automatically the right trade-off for every project – a slim or alpine variant sometimes means a different C library (musl vs glibc) that can introduce its own compatibility issues worth testing for before adopting it purely for size.

A bloated Docker image is rarely one bad decision – it’s a dozen small, locally-reasonable ones that nobody added up until the registry bill or the deploy time forced the question.

— AI Power User

Related posts:

AI Prompt: Generate Sales Emails That Close Deals

AI Prompt — Code Risk Scanner

AI Prompt: Optimize SQL Queries with Execution Plan Analysis

Post Views: 3

Post navigation

SQL Server: Fix a Query That Returns Different Row Counts Depending on the Session’s Isolation Level
The AI Prompt That Turns a Stack of School Permission Slips and Forms Into One Calendar List

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

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

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

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

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

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