<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Swapnil Strange on Medium]]></title>
        <description><![CDATA[Stories by Swapnil Strange on Medium]]></description>
        <link>https://medium.com/@swapnil.strange0707?source=rss-feb7f29e62e8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Ie49LeS-Md5AWGgP</url>
            <title>Stories by Swapnil Strange on Medium</title>
            <link>https://medium.com/@swapnil.strange0707?source=rss-feb7f29e62e8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:29:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swapnil.strange0707/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[4S Mastery: From Bulky RVs to Secured Backpacks — The Ultimate Guide to Docker Security]]></title>
            <link>https://medium.com/@swapnil.strange0707/4s-mastery-from-bulky-rvs-to-secured-backpacks-the-ultimate-guide-to-docker-security-de9f03ca1cba?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/de9f03ca1cba</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[docker-security]]></category>
            <category><![CDATA[dockerfile-best-practice]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 04:42:47 GMT</pubDate>
            <atom:updated>2026-02-16T04:49:44.861Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*KJCLIOOAJr6BQfz3LejLzw.png" /></figure><p>When we are breaking down the basics of a Dockerfile, security isn’t really something we discuss too much. One reason is that you need to be familiar with Docker fundamentals, base images, and multi-stage builds to understand the nuances of security practices. In case you are not, the following articles explain these concepts with the simplest possible analogies:</p><ul><li><a href="https://medium.com/@swapnil.strange0707/the-house-replica-machine-understanding-dockerfiles-4dfea933b5a8"><strong>Docker Fundamentals</strong></a></li><li><a href="https://medium.com/@swapnil.strange0707/the-michelin-star-dockerfile-why-your-production-image-doesnt-need-the-whole-kitchen-0f0a49da7ec7"><strong>Multi-Stage Builds</strong></a></li><li><a href="https://medium.com/@swapnil.strange0707/packing-light-the-art-of-docker-image-size-406bb52ccc60"><strong>Size Optimization using Base Images</strong></a></li></ul><p>Assuming you do have a basic understanding of the different Docker components, let’s zoom into a couple of best practices. We implement multi-stage builds to ensure our deployed production image only contains the necessary files, and irrelevant content is filtered out. Similarly, we use lighter base images for production. While these boost speed and reduce size, they also make a very important contribution to the overall security of the system.</p><p><strong>Attack Surface: The RV vs. The Backpack</strong></p><p>Think back to our <strong>RV to Backpack</strong> analogy comparing :latest tags to Google’s “distroless” images. As the RV has more moving parts, there are more scenarios where something could go wrong: tire punctures, fuel leaks, parking issues, or a broken fridge. You have more things to safeguard.</p><p>Similarly, in a container, the bigger the image, the larger the <strong>“surface area”</strong> for an attack. There are more binaries, libraries, and tools where an attacker might find a vulnerability. Thus, the first step in security is implementation: keep the image as small as possible while keeping the functionality intact.</p><p>Prevention is great, but what about <strong>mitigation</strong>? What if something <em>does</em> get compromised? This leads us to ownership of files and allocated permissions.</p><p><strong>A Detour into Linux Fundamentals</strong></p><p>Most containers run in a Linux environment, so we’ll use Linux as our main consideration. In Docker, every file and folder is created with a specified ownership and a set of permissions. If you run “ls -la” on a folder, you will see permissions in the first column and the user/group attached to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*ePk09uR0i3ndkGjNaTxzNA.png" /><figcaption>Screenshot of running ls -la comand in Bash</figcaption></figure><p>(The d in the first column simply refers to a directory/folder)</p><p>One way to represent these permissions is through numeric digits:</p><ul><li><strong>4</strong> represents <strong>Read</strong></li><li><strong>2</strong> represents <strong>Write</strong></li><li><strong>1</strong> represents <strong>Execute</strong></li></ul><p>So <strong>6 (4+2)</strong> means read and write permissions. <strong>7 (4+2+1)</strong> means full permission. If we go back to the attached screenshot, you’ll notice the permissions (like rwxr-xr — ) are spaced three times. These represent the permissions for the <strong>User</strong>, the <strong>Group</strong>, and <strong>Others</strong>.</p><p>For example, rwxr-xr — (or <strong>754</strong>) means:</p><ol><li><strong>User:</strong> Has all permissions (Read, Write, Execute).</li><li><strong>Group:</strong> Has only Read and Execute.</li><li><strong>Others:</strong> Has only Read permissions.</li></ol><p><strong>What are Users and Groups?</strong> Think of a company with Billing, Accounting, and HR departments. Each has permissions specific to their needs. An “Administrator” (the Executive Board) has all permissions. In Linux, you have groups with specialized permissions, and the <strong>“root”</strong> user has all the permissions. Anyone hired into the Billing department (a “User”) gets that department’s permissions by default.</p><p><strong>Understanding File vs. Folder Permissions</strong></p><p>Permissions can sometimes be confusing. A folder’s permissions do not automatically translate to the files inside.</p><ul><li><strong>Folder Read:</strong> Allows you to ls (see the contents), but not necessarily read the files inside.</li><li><strong>Folder Write:</strong> Allows you to create or delete files in the folder, but not necessarily modify the content of existing files.</li><li><strong>Folder Execute:</strong> Allows you to cd (traverse) through the folder.</li></ul><p>In Linux, we use chown and chmod to modify these:</p><ul><li>chown user1:group1 xyz.txt (Changes who owns the file)</li><li>chmod 775 xyz.txt (Changes what they can do with it)</li></ul><p><strong>The Goal: Least Possible Privilege</strong></p><p>Why do we do this? To maintain the most fundamental security practice: <strong>Least Possible Privilege.</strong> We ensure that access to a resource is limited to exactly what it needs to function.</p><p>Think of your company again. If the credentials of someone in the Reporting department are breached, you don’t want the attacker to automatically get access to the Billing info or the Admin systems. Similarly, we ensure each resource in our system has only the privileges it needs. Even if an attacker gains access, the damage they can cause is strictly limited.</p><p><strong>Applying Security to your Dockerfile</strong></p><p>As we’ve discussed, the best Dockerfiles are multi-staged.</p><p><strong>1. The Builder Stage:</strong> Here, we use heavy base images because we need to install packages and compile code. These tasks often need administrative (“root”) privileges. So, in the builder stage, it makes sense to stay as the root user.</p><p><strong>2. The Production Stage:</strong> This is where we expose our application to the outside world. Here, we need to apply the “Least Privilege” rule.</p><ul><li><strong>Files:</strong> Most files only need 5 (Read and Execute) to run.</li><li><strong>User:</strong> By default, containers run as <strong>root</strong>. This is risky. If an attacker gains access, they have the “keys to the kingdom.” It is a best practice to run the container as a <strong>non-root user</strong>.</li></ul><p>You will often see this implemented in two lines:</p><pre>COPY --from=builder --chmod=755 /app /app<br>USER non_root_user</pre><p>Here, we copy files with 755 permissions (Root can write, others can only read/execute) and then switch the USER away from root.</p><p><strong>Why stay as “root” for ownership?</strong> You might wonder: <em>“Why not use chown to make the non-root user the owner of the files?”</em></p><p>Let’s look deeper. In Linux, only the <strong>owner</strong> of a file can change its permissions (chmod). If an attacker gains access as your “non_root_user” and that user <strong>owns</strong> the files, the attacker can simply run chmod 777 and give themselves full write access to your code!</p><p>By keeping the ownership with <strong>root</strong> but running the application as a <strong>non-root user</strong>, the attacker is trapped. They aren’t the owner, so they can’t change the permissions we set. They are stuck with the “Read-Only” access we gave them.</p><p><em>(Note: We use 755 instead of 555 because root occasionally needs momentary write access for configurations during the container’s startup process before it hands over control to your user.)</em></p><p><strong>What is a “Non-Root” User?</strong></p><p>It is simply a user without admin privileges. Most official images provide one by default (e.g., the node image has a user called node). If your image doesn’t have one, you can create it yourself:</p><p>Dockerfile</p><pre>RUN addgroup -S appgroup &amp;&amp; adduser -S appuser -G appgroup<br>USER appuser</pre><p><strong>In Conclusion</strong></p><p>To keep your containers safe:</p><ol><li><strong>Use Multi-Stage builds</strong> to keep the image small and reduce the “attack surface.”</li><li><strong>Use Least Privilege:</strong> Keep file ownership with root, but run your application as a non-root user.</li></ol><p>By following the <strong>4 S’s — Speed, Stage, Size, and Security, </strong>you aren’t just making a Dockerfile; you’re building a professional, production-ready environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de9f03ca1cba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Packing Light: The Art of Docker Image SIZE]]></title>
            <link>https://medium.com/@swapnil.strange0707/packing-light-the-art-of-docker-image-size-406bb52ccc60?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/406bb52ccc60</guid>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[alpine]]></category>
            <category><![CDATA[distroless]]></category>
            <category><![CDATA[image-size-reduce]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 05:10:31 GMT</pubDate>
            <atom:updated>2026-02-14T05:10:31.981Z</atom:updated>
            <content:encoded><![CDATA[<p>We started with the first S of Docker: <strong>Speed</strong>. Today, we focus on the 3rd S: <strong>SIZE</strong>.</p><p>To get the most out of this, you’ll want a basic idea of what “Staging” is. If you missed it, check out the previous article where I explain it using a Michelin-star kitchen:</p><p><a href="https://medium.com/@swapnil.strange0707/the-michelin-star-dockerfile-why-your-production-image-doesnt-need-the-whole-kitchen-0f0a49da7ec7"><em>Multi-Stage Builds</em></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*s85qP3wqCxVQkkfkINmiGg.png" /></figure><p><strong>Why does size even matter?</strong></p><p>Think of packing a bag for a long trip. The more things you have, the heavier it is to carry around. It costs you more in baggage fees, you might have to buy extra bags to fit everything, and you must constantly keep tabs on a dozen different zippers.</p><p>In Docker, a bulky image “hogs” resource. You pay more for storage, it takes longer to pull the image over the network, and most importantly, a larger image has a bigger “attack surface” (more places for a hacker to hide).</p><p><strong>The Evolution of the Trip: From RV to Backpack</strong></p><p>Every stage in a Dockerfile starts with a base image (the FROM line). This is the “environment” your app lives in. But you have a choice in how much “environment” you actually take with you.</p><p><strong>Here is how the transformation looks in your code:</strong></p><pre>FROM node:latest      # The RV (Everything including the kitchen sink)<br>FROM node:slim        # The Family Car (Practical and fast)<br>FROM node:alpine      # The Motorcycle (Stripped down to the frame)<br>FROM distroless/node  # The Backpack (Just you and the road)</pre><p><strong>1. The RV (node:latest / node:dev)</strong></p><p>This image comes out of the box with <em>everything</em>. It has the full C GNU library, package managers, debugging tools, and every utility you could possibly imagine.</p><ul><li><strong>The Analogy:</strong> You’ve rented a massive RV. You have a kitchen, a shower, and a king-sized bed. You won’t lack anything, but it’s expensive to fuel, a nightmare to park, and very slow on winding roads.</li><li><strong>The Technicality:</strong> If you run npm install inside this, you never have to worry about a missing library. It’s the “safest” bet for your <strong>Builder Stage</strong>.</li></ul><p><strong>2. The Car (node:slim / node:alpine)</strong></p><p>These are the “lightweight” contenders. We drop the unnecessary tools and keep only the bundled-up, smaller versions of the essentials.</p><ul><li><strong>The Analogy:</strong> You’ve switched to a reliable car. You can travel faster and it’s more practical, but sleeping might be a bit uncomfortable and you have to find food on the road.</li><li><strong>The Technicality:</strong> Slim uses the standard library (glibc), while Alpine uses a tiny version called musl. They are small, but they still give you a “shell” (a terminal) so you can hop in and fix things if the trip goes sideways.</li></ul><p><strong>3. The Backpack (Distroless)</strong></p><p>Maintained by Google, these are the lightest and fastest of them all. There is no shell, no package manager, nothing but your compiled application.</p><ul><li><strong>The Analogy:</strong> You’ve ditched the vehicle. You have your backpack, a sleeping bag, and your phone. You have the least to take care of, you travel the lightest, and you have zero parking issues.</li><li><strong>The Technicality:</strong> It is incredibly secure because a hacker can’t even run a “list files” command if they get in. However, if you need to debug the container while it’s running, you’re out of luck — you don’t even have a terminal to type in.</li></ul><p><strong>How to Choose Your Mode of Travel</strong></p><p>Just like a real trip, your choice depends on the “passengers” and the destination:</p><ul><li><strong>Building the app?</strong> Take the <strong>RV (Latest)</strong>. You need the space and the tools to get the work done comfortably.</li><li><strong>Testing or Dev environments?</strong> Take the <strong>Car (Slim/Alpine)</strong>. It’s fast and cheap, but still lets you “get out and check the engine” (debug) if needed.</li><li><strong>Heading to Production?</strong> Take the <strong>Backpack (Distroless)</strong>. Once the code is tested and you know it won’t change, there’s no reason to carry the extra weight.</li></ul><p>In short: your image depends on your use case. Pack only what you need, and your deployments will thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=406bb52ccc60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Michelin Star Dockerfile: Why Your Production Image Doesn’t Need the Whole Kitchen]]></title>
            <link>https://medium.com/@swapnil.strange0707/the-michelin-star-dockerfile-why-your-production-image-doesnt-need-the-whole-kitchen-0f0a49da7ec7?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/0f0a49da7ec7</guid>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[multi-stage-dockerfile]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dockerfile-example]]></category>
            <category><![CDATA[dockerfile-best-practice]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Sat, 14 Feb 2026 05:08:18 GMT</pubDate>
            <atom:updated>2026-02-16T04:52:46.623Z</atom:updated>
            <content:encoded><![CDATA[<p>In our last article, we talked about the 4 S’s of Docker. Today, we’re diving into the second S: <strong>STAGE</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*ufRtG6_3Dz_BkZfKLy9_jw.png" /></figure><p>If you missed the first S (<strong>Speed</strong>), you can check it out: <a href="https://medium.com/@swapnil.strange0707/the-need-for-speed-why-your-dockerfile-order-matters-c33224505cb3"><em>[Speedin up Docker]</em></a>, though you don’t strictly need it to understand STAGE. And if you’re brand new to Docker and want the most non-technical intro possible, visit <a href="https://medium.com/@swapnil.strange0707/the-house-replica-machine-understanding-dockerfiles-4dfea933b5a8"><em>here</em></a>.</p><p>Now, enough self-promotion. Let’s talk about <strong>STAGE</strong>.</p><p><strong>Why do we even need “Stages”?</strong></p><p>Before we define what a stage is, let’s look at why they exist. While stages help with isolation and security, the biggest win is avoiding <strong>“Image Bloat.”</strong></p><p>Think about how we build software:</p><ul><li><strong>Frontend (React/Angular):</strong> The browser doesn’t actually run the thousands of files in your src folder. It only needs the “compiled” static files (usually in a dist or build folder).</li><li><strong>Backend (Java/Go):</strong> These are compiled languages. You write the code, but the server runs a “binary” or a “JAR” file. Once that file is created, you don’t actually need the source code or the heavy compiler anymore.</li></ul><p><strong>If the final service only uses the compiled folder, why should we bloat our image with all those unnecessary files?</strong></p><p>Think of a kitchen in a Michelin-star restaurant. The chefs use a massive variety of raw ingredients, heavy pots, and specialized tools to create your meal. But when the waiter brings out the food, it’s a small, perfectly “compiled” dish.</p><p>We don’t need the leftover vegetable scraps, the heavy stockpots, or the raw flour on our table. Not only would that make the plate messy, but it would also make it heavy for no reason!</p><p>This is where <strong>Multi-Stage builds</strong> kick in.</p><ol><li><strong>The Kitchen (Builder Stage):</strong> This is where things are made. It’s busy, full of tools, and contains all your source code and compilers.</li><li><strong>The Table (Production Stage):</strong> This is your final image. It’s a light, beautiful plate with <em>exactly</em> what the customer (the user/server) needs to eat.</li></ol><p><strong>So, what is a Stage?</strong></p><p>In Docker, a “Stage” is a logical separation of tasks. Every time you write FROM in a Dockerfile, you are starting a new stage. The “magic” is that <strong>only the very last stage</strong> becomes your final image.</p><p>Every stage can interact with the ones before it. You can build something in Stage 1, and then “reach back” and grab just the finished product to put into Stage 2.</p><p><strong>Example: A Basic Java Multi-Stage Build</strong></p><p>Here is how this looks in the real world using a Java (Maven) backend. We use the first stage to build the app and the second stage to run it.</p><pre># STAGE 1: The Kitchen (The Builder)<br>FROM maven:3.9-eclipse-temurin-17 AS builder<br>WORKDIR /app<br><br># Copy the &quot;Ingredients&quot; (Source code)<br>COPY . .<br><br># Compile the &quot;Dish&quot; (The JAR file)<br>RUN mvn clean package -DskipTests<br><br># STAGE 2: The Table (The Production Image)<br>FROM eclipse-temurin:17-jre-alpine<br>WORKDIR /app<br><br># Reach back into the kitchen and grab ONLY the finished dish<br>COPY - from=builder /app/target/my-app-1.0.jar app.jar<br><br># Serve the dish<br>ENTRYPOINT [&quot;java&quot;, &quot;-jar&quot;, &quot;app.jar&quot;]</pre><p><strong>Sequential vs. Parallel</strong></p><p>In the example above, Stage 2 is <strong>dependent</strong> on Stage 1 because it needs that .jar file. Therefore, they run one after the other.</p><p>However, Docker is smart. If you have stages that don’t depend on each other — say, one stage for <strong>Unit Testing</strong> and another for <strong>Linting</strong> — Docker will run them at the same time (in parallel). It’s like putting meat on the grill while the sauce is being prepared in a separate pan. Neither needs to wait for the other to start.</p><p><strong>The Result</strong></p><p>By using Multi-Stage builds, you get a final image that is significantly smaller, faster to deploy, and more secure (because there’s no source code for a hacker to look at if they get inside).</p><p>We’ll dive deeper into <strong>Size</strong> and <strong>Security</strong> in the next articles, but for now, remember: don’t bring the whole kitchen to the dinner table!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0f0a49da7ec7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Need for Speed: Why Your Dockerfile Order Matters]]></title>
            <link>https://medium.com/@swapnil.strange0707/the-need-for-speed-why-your-dockerfile-order-matters-c33224505cb3?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/c33224505cb3</guid>
            <category><![CDATA[docker-speed]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 04:37:22 GMT</pubDate>
            <atom:updated>2026-02-13T04:37:22.385Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*3kO2c1qjlZUnUVJqcX_5tQ.png" /></figure><p>When we speak of Docker, there are <strong>4 S’s</strong> that we need to consider to get the most out of containerization: <strong>Speed, Stage, Size, and Security.</strong></p><p>Today, let’s start with <strong>SPEED</strong>.</p><p>Take a look at these two ways of writing a Dockerfile. On the surface, they look like they do the exact same thing:</p><p><strong>Approach 1:</strong></p><pre>COPY . .<br>RUN npm ci</pre><p><strong>Approach 2:</strong></p><pre>COPY package.json package-lock.json ./<br>RUN npm ci<br>COPY . .</pre><p>In both cases, at the end, the source code is copied and the packages are downloaded. So, is there really a difference? On the surface, it looks like in Approach 2 we have to write more just to copy files separately, and we might be inclined to go for the simpler approach. But here is where the way Docker is configured — using <strong>“layers, </strong>becomes important.</p><p><strong>Mike Ross and his Photographic Memory</strong></p><p>In Docker, each line we write constitutes a separate “layer.” When we start with FROM node:18-alpine, we set a base layer, and every step after that is a layer on top of it.</p><p>The biggest benefit of this is <strong>Caching</strong>. Docker caches each layer once it’s built and maintains a checksum for each one. You can check this out yourself: build an image, then build it again without changing anything. The second build will be way quicker because it uses the cache rather than repeating the work.</p><p>Have you guys seen <em>Suits</em>? Consider <strong>Mike Ross</strong>. He has a photographic memory. If you give him a new book and ask him questions, he has to read through it the first time to answer (which takes time). But once he’s read it, he remembers every detail and can answer you immediately.</p><p>However, there is a specific rule to how Mike’s memory works: <strong>Docker’s caching is a “domino effect.”</strong> The way it works is that if a checksum fails for a layer (say Layer 3), Docker doesn’t just re-read that page; it invalidates the cache for that layer <strong>and every single layer that follows it.</strong> It assumes that if the foundation changed, everything built on top of it might be different, too.</p><p><strong>Revisiting Our Approaches</strong></p><p>Now that we know that, let’s revisit our two approaches.</p><p><strong>In Approach 1:</strong> We copy the whole source code (Layer 1) and then install dependencies (Layer 2). As we know, running npm ci or pip install takes a long time because dependencies are being fetched from remote places.</p><p>If you change even a single character in your source code, Layer 1’s checksum fails. Because Layer 1 is now “new,” Docker is forced to throw away the cache for Layer 2. This means even if you haven’t added any new packages, a tiny code change forces you to wait through a full dependency installation all over again.</p><p><strong>In Approach 2:</strong> This is exactly what gets solved here. Since we are copying <strong>only</strong> the dependency files first, and the source code is copied <em>after</em> the installation is done, the layers are separated.</p><p>You can change your source code as much as you want! As long as your package.json stays the same, Docker will use the cache for the time-consuming installation step. This reduces your build time significantly after the first run.</p><p><strong>“What if I change a dependency?”</strong></p><p>You might be wondering: <em>“What if I actually add a new package?”</em> You’re right — in that case, the installation will happen from scratch and take time. But in any long-running project, the number of times you update a package is tiny compared to the number of times you change your source code.</p><p><strong>A Quick Note: npm i vs npm ci</strong></p><p>You might be more familiar with npm i. In general terms, <strong>npm ci</strong> is designed for “Continuous Integration” (like Docker builds). It uses the package-lock.json to install the <strong>exact</strong> version of your dependencies. If there is a mismatch between the lock file and your package.json, it would simply fail.</p><p>npm i, on the other hand, might try to fix discrepancies or update versions on the fly. While npm ci requires you to ensure your files are consistent, it is faster and much more reliable to ensure your Docker container works exactly like your local environment.</p><p><em>(P.S. If you are using Python, hurrah! You don’t have to worry about the ci vs i distinction. Just copy your requirements.txt first, run your pip install, and then copy your source code. You’ll get the same massive speed boost!)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c33224505cb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The House Replica Machine: Understanding Dockerfiles]]></title>
            <link>https://medium.com/@swapnil.strange0707/the-house-replica-machine-understanding-dockerfiles-4dfea933b5a8?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dfea933b5a8</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[commands]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 04:34:58 GMT</pubDate>
            <atom:updated>2026-02-13T04:34:58.327Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jMiFcDCcsbtwtVRe" /></figure><p>So, let’s talk about Docker. Now, if you have been referred here through my LinkedIn Post, you might have had a ton of information just thrown at you. If not, well, that makes things easy for us to start.</p><p>Some of you might already know what Docker is or what it is good for. If you don’t have the technical nuances of why we need Docker yet and would like to get into that, you can refer to this link:</p><p><a href="https://www.geeksforgeeks.org/blogs/why-should-you-use-docker-7-major-reasons/">Why Should You Use Docker - 7 Major Reasons! - GeeksforGeeks</a></p><p><strong>Docker: The Replica Machine</strong></p><p>For this discussion, I want to compare a <strong>Dockerfile</strong> to a highly trained machine capable of making perfect replicas of whatever house you give it an image of.</p><p>To make a replica, the machine first needs <strong>Paper</strong>. You know how different types and qualities of paper serve different purposes (lined, graph, or canvas)? The “paper” determines the foundation of your replica. In Docker, we call this the <strong>Base Image</strong>.</p><p>Next, your machine needs to set its <strong>Tools</strong>, the types of pencils, markers, and rulers, based on your specific design. These are your <strong>Dependencies</strong> (like npm or yarn packages).</p><p>Then comes your <strong>Design</strong>. The machine has to copy your design into its own system, line by line and curve by curve, to ensure perfect replication. Finally, the machine refers to this design using the tools required, makes your replica, and packages it in a <strong>Box</strong>. Every time you open that box, you get your house exactly as intended.</p><p>Consider the application (client/server) you have built as this “Design” to be replicated. Docker makes perfect replicas and packages them into a <strong>Container</strong> (the box). Whenever you run the instructions, it pops out your application just as you intended, every single time.</p><p><strong>Anatomy of a Dockerfile</strong></p><p>Let’s look at what a normal Dockerfile looks like for Node.js and understand what each step fundamentally does.</p><pre># 1. Base image (The &quot;Paper&quot;)<br>FROM node:18-alpine<br><br># 2. Set working directory (The &quot;Desk&quot;)<br>WORKDIR /app<br><br># 3. Copy application files (The &quot;Design&quot;)<br>COPY . .<br><br># 4. Install dependencies (The &quot;Tools&quot;)<br>RUN yarn install --production<br><br># 5. Start the application (The &quot;Instructions&quot;)<br>ENTRYPOINT [ &quot;node&quot;, &quot;src/index.js&quot; ]<br><br># Metadata<br>EXPOSE 3000</pre><p><strong>1. FROM node:18-alpine</strong></p><p>Since our base application is built on top of Node, we need Node to execute it, just like you need to install Node on your system before you run any .js file. In our analogy, this is the <strong>Paper</strong> our machine builds everything on top of. We use alpine because it’s a lightweight, “thin” paper that keeps things fast.</p><p><strong>2. COPY . . [COPY &lt;src&gt; &lt;dst&gt;]</strong></p><p>You need to copy the source code from your local machine to the container. This command says: “Whatever is in the present directory (.) of my local machine, copy it to the present directory of the Docker image.” This is our machine copying the <strong>Design</strong> into its own memory so it knows what it is building.</p><p><strong>3. RUN yarn install</strong></p><p>Just like you need to install your dependencies locally, you need to install them inside the image too. This is our machine configuring all the <strong>Tools</strong> it needs for this specific image. Different designs might need different tools, just like different code needs different packages.</p><p><strong>4. ENTRYPOINT</strong></p><p>This is an array of strings representing commands, basically mirroring the commands you would run on your terminal if you wanted to start your application. These are the <strong>Instructions</strong> on how to “open the box” and access the application whenever we want.</p><p><strong>5. WORKDIR and EXPOSE</strong></p><p>Your application would still run fine without these, but they are best practices:</p><ul><li><strong>WORKDIR</strong>: By default, COPY . . copies everything to the root directory of our image. It’s best practice to keep things contained; WORKDIR /app means we are giving the machine a specific <strong>Desk</strong> to work on so our files aren’t scattered.</li><li><strong>EXPOSE</strong>: This is just <strong>Metadata</strong>. It has no function of its own, but it’s a helpful note to developers to understand which port the server is listening on (like app.listen(3000)).</li></ul><p><strong>Bringing it to Life: Build and Run</strong></p><p>To see results, we need two commands. <strong>Building</strong> is the machine creating the final image, and <strong>Running</strong> is packaging it into a box and opening it.</p><p><strong>The Build Command:</strong></p><pre>docker build -t &lt;name-of-image&gt; .</pre><ul><li>The period (.) refers to the directory where your Dockerfile is.</li><li>This assumes the file is named “Dockerfile.” If not, you’ll need to specify the filename.</li></ul><p><strong>The Run Command:</strong></p><pre>docker run -p 3000:3000 &lt;image-name&gt;</pre><p>This brings us to our <strong>Magic Doorway</strong> analogy for the -p 3000:3000 flag. Your replica house is sitting inside a sealed-off bubble (the container). It has a front door (Port 3000), but you are standing outside on the street (your laptop). To get inside, you need to build a doorway that connects the two:</p><ul><li><strong>The first 3000</strong> is the door on the <strong>Street</strong> (your computer). You type localhost:3000 in your browser to reach it.</li><li><strong>The second 3000</strong> is the door on the <strong>House</strong> (the container).</li></ul><p>When you run this, you are telling Docker: <em>“When I knock on Door 3000 on my street, instantly teleport me to Door 3000 inside the house bubble.”</em></p><p><strong>Useful Commands to Remember:</strong></p><ul><li>docker images: Check all current replica designs (images) you’ve created.</li><li>docker ps: Check all current boxes (containers) that are actually open and running.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dfea933b5a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallelizing the Brain: Speeding up LLM Calls in Python]]></title>
            <link>https://medium.com/@swapnil.strange0707/parallelizing-the-brain-speeding-up-llm-calls-in-python-aa6bda19c547?source=rss-feb7f29e62e8------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa6bda19c547</guid>
            <category><![CDATA[parallel-processing]]></category>
            <category><![CDATA[llms-utilization]]></category>
            <category><![CDATA[speed]]></category>
            <category><![CDATA[parallelism]]></category>
            <category><![CDATA[ai-speed]]></category>
            <dc:creator><![CDATA[Swapnil Strange]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 06:31:01 GMT</pubDate>
            <atom:updated>2026-02-04T06:31:01.234Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RmN9jpAjPG-EoOk-gVTUnQ.png" /></figure><p>The launch of ChatGPT in 2022 with its GPT-3.5 generative model kickstarted a whole new era, especially in the field of software development. The models that we have access to today far exceed the capabilities of that 2022 model, from advanced voice translation and reasoning to powerful image and video generation (you will see a lot of that being used in this article 😊 ), up massive opportunities for streamlining real-world use cases.</p><p>The release of Agentic systems, Skills, and advanced RAG capabilities helps streamline complex workflows, but at the backend, we are still dealing with an API call made to the LLM. In fact, a lot of the work we deal with can be achieved through these calls, especially with the ever-increasing context window.</p><p><strong>The Case for Parallelization</strong></p><p>But what if we have to process a huge amount of data, resulting in multiple LLM calls? If we proceed sequentially, it will take forever to complete our requests, resulting in a bad user experience.</p><p>Imagine being in line to get into a Temple or a Taylor Swift concert. If there was a singular gate and everyone stood in a single line, the time it would take for everyone to get in would make <em>Bangalore traffic feel like a walk in the park</em>. Ideally, they would have multiple gates and split up the crowd into multiple lines.</p><p>This is precisely what parallelization is. We allow multiple events to run in parallel, provided they don’t depend on each other. Keep in mind, these tasks must be independent; for instance, performing the same operation on different chunks of data. If the tasks are independent, it’s a perfect case for parallelization.</p><p><strong>Execution Models: Multiprocessing vs. Multithreading</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C74TLyAfexPvtdaU5TVemg.png" /></figure><p>So, how do we achieve it? If you search Google, you’ll come across multiprocessing, multithreading, or asynchronous programming. To understand which is best for LLM calls, let’s look at a kitchen.</p><p>Imagine a chef who can do all the bits to prepare his special dish, making desserts, grilling meat, and preparing the sauce. If he’s just making one dish, he handles it fine. <strong>But what if a large amount of orders for this dish suddenly comes up?</strong> That’s when he needs help. He sends in two people, Cheryl and Pete. One takes over dessert, the other grills meat, while the chef focuses on the sauce.</p><p>There we go: parallelism. But consider two scenarios. First, they all work at the same workstation with the same tools. This makes communication easy but can get messy — what if the chef needs the knife Pete currently has? Working in tight spaces leads to collisions. Alternatively, we could give them separate workstations and tools. This provides isolation and efficiency. While communication is harder, we have better security.</p><p>The same applies to our systems. The “helpers” are your CPU cores. Working with the same tools is “shared memory,” which makes it easy for threads to talk but can lead to a “deadlock” (like the knife situation). Multiprocessing gives each their own “workstation” (memory). It’s more resource-intensive to communicate, but it’s more secure and isolated.</p><p><strong>Understanding Blocking and Asynchronous Tasks</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PBQshF93-zt5iKgUeaZ8Q.png" /></figure><p>What about asynchronous programming? To understand this, we need to talk about “Blocking” and “Non-blocking” events. Sticking with our restaurant theme, consider putting veggies to boil. Does someone need to stand there and wait till it boils? Not really. We can let it boil and check on it later. But what about chopping onions? Someone needs to be consistently present for that.</p><p>Chopping onions is a <strong>blocking</strong> event (the CPU is intensively involved), while boiling water is <strong>non-blocking</strong> (the CPU sends the task elsewhere and waits).</p><p>There is one more nuance: compatibility. All API calls can’t be asynchronous because the server or DB needs to support it. Think of it like a toaster or an oven; they have a timer and make a sound when they are done. That “timer” is what’s needed for async code. Water boiling in a pot is non-blocking, but if it doesn’t have a timer to notify us, we can’t easily use it for asynchronous programming.</p><p><strong>Python and the Global Interpreter Lock (GIL)</strong></p><p>Now, which one boosts our LLM calls? Since most AI servers are built on Python, let’s focus there. Python has something called the Global Interpreter Lock (GIL). In our kitchen, imagine things are getting messy, so we introduce a Manager (the GIL). The manager decides that only one person can execute one task at a time, switching between them after a set period.</p><p>Cheryl whips cream for a minute, then she freezes, and the chef chops an onion for a minute. This means in Python, we lose the sense of “true” multi-threading for blocking tasks like chopping onions. But what about the guy who has two non-blocking jobs: boiling water and putting meat on the grill? Even with a GIL, he can put water to boil, then, since that’s non-blocking, he can immediately go put meat on the grill.</p><p>In conclusion, we lose true multi-threading for heavy CPU tasks, but non-blocking events can still be parallelized. Multiprocessing still works, but it’s like having one Manager (GIL) per workstation. It’s costly and limited by your hardware.</p><p><strong>Optimization Strategies for LLM Workloads</strong></p><p>So, how do we parallelize LLM calls? Let’s look at the call again. We call an API and wait for a response while the LLM “thinks” on its own server. Our server isn’t doing the thinking; it’s just waiting. You guessed it, this is a <strong>non-blocking</strong> operation. We can use asynchronous programming or multi-threading to achieve this.</p><p>The choice depends on your setup. Asynchronous programming needs support (the “timer”), and while most modern libraries support it, your choice of server matters. FastAPI supports it, whereas Flask traditionally doesn’t. Threads, meanwhile, are an overhead to manage but are compatible across the board.</p><p>For instance, Langchain’s .batch() method uses Multithreading (ThreadPoolExecutor). Since Langchain is a wrapper for many services, some of which support async and some which don’t, they went with the option that works with everything.<br> <br> In Python, you can implement multithreading using <a href="https://docs.python.org/3/library/concurrent.futures.html">ThreadPoolExecutor</a>, multiprocessing using <a href="https://docs.python.org/3/library/concurrent.futures.html#processpoolexecutor">ProcessPoolExecutor</a>, and asynchronous programming using the <a href="https://docs.python.org/3/library/asyncio.html">asyncio </a>library.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa6bda19c547" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>