<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: nonroot_ops</title>
    <description>The latest articles on DEV Community by nonroot_ops (@nonroot_ops).</description>
    <link>https://dev.to/nonroot_ops</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4263193%2F8a5371a9-46ae-47f0-b164-7a69a921f756.png</url>
      <title>DEV Community: nonroot_ops</title>
      <link>https://dev.to/nonroot_ops</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nonroot_ops"/>
    <language>en</language>
    <item>
      <title>Your On-Call Team Isn't Ignoring Alerts. Your Alerts Are Lying to Them.</title>
      <dc:creator>nonroot_ops</dc:creator>
      <pubDate>Tue, 24 Nov 2026 20:55:39 +0000</pubDate>
      <link>https://dev.to/nonroot_ops/your-on-call-team-isnt-ignoring-alerts-your-alerts-are-lying-to-them-hn6</link>
      <guid>https://dev.to/nonroot_ops/your-on-call-team-isnt-ignoring-alerts-your-alerts-are-lying-to-them-hn6</guid>
      <description>&lt;p&gt;It's 2:14 a.m. Your phone buzzes for the fourth time this week with "CPU &amp;gt; 80% on worker-7." You squint at the dashboard, see nothing wrong, and go back to sleep. Nobody on the team thinks of that as negligence. It's just what happens when the alerting system cries wolf for two years.&lt;/p&gt;

&lt;p&gt;Let's get one thing out of the way. When an on-call engineer starts ignoring alerts, the engineer isn't the problem. Someone built a system that trains people to ignore it, and then acted surprised when they did. I say this as someone who has written plenty of alerts that made my own phone unbearable. Alert fatigue is a design failure, and most of the time it's ours.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Alerts Should Mean "A Human Must Act Now"
&lt;/h2&gt;

&lt;p&gt;Here's the test I use for every alert: if this fires at 3 a.m., should a person wake up and do something specific right away? If the answer is "probably not, but it might be interesting," that alert doesn't belong in a paging channel. It belongs in a dashboard, a log, or a ticket queue that someone reviews on Monday.&lt;/p&gt;

&lt;p&gt;Most noisy alert setups fail this test in one of three ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;They fire on causes, not on user pain.&lt;/strong&gt; CPU at 80% sounds scary, but if users are happy, CPU at 80% is just a fact about your hardware.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They fire on thresholds nobody can justify.&lt;/strong&gt; Ask who picked 500 ms, and the honest answer is usually "it felt right in 2019."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They fire and then resolve on their own.&lt;/strong&gt; If an alert flaps every few minutes, it's teaching your team that the pager is a suggestion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every alert that doesn't meet the bar is a small tax on your team's attention. Pay that tax enough times and people stop paying attention at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Cause Alerts vs. Symptom Alerts
&lt;/h2&gt;

&lt;p&gt;This is the distinction that changed how I think about alerting. A cause is something inside your system that might hurt users: a full disk, a slow database replica, a pod restart loop. A symptom is something users actually feel: errors, slow pages, failed checkouts.&lt;/p&gt;

&lt;p&gt;Cause-based alerts are tempting because they feel actionable. "Disk at 90%" sounds like a clear task. But many causes never become a problem for anyone. The disk fills slowly, a cleanup job runs, and nobody notices. Meanwhile, the one cause that does matter might not have an alert at all.&lt;/p&gt;

&lt;p&gt;Symptom-based alerts flip that around. You page when users are hurting, and you use causes for debugging after the page. Your dashboards and logs can be full of cause metrics. Your pager should be almost entirely symptoms.&lt;/p&gt;

&lt;p&gt;I know this idea gets pushback. "But what if the disk fills up and takes us down?" Then the symptom alert will fire when users start failing, and the disk alert becomes a ticket that gets handled during business hours. You lose a few minutes of lead time. You gain a team that actually answers the phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. SLOs Give You a Budget, Not a Feeling
&lt;/h2&gt;

&lt;p&gt;A Service Level Objective (SLO) puts a number on "good enough." For example: 99.9% of requests succeed over a rolling 30 days. That gives you an error budget, the amount of failure you're allowed before you've broken your promise. For 99.9% over 30 days, that's about 43 minutes of full outage, or an equivalent amount of partial failure spread out.&lt;/p&gt;

&lt;p&gt;The useful part is that the budget turns a vague question ("is this bad?") into a measurable one ("how fast are we spending the budget?"). That speed is called the burn rate. A burn rate of 1 means you'll use exactly your budget by the end of the window. A burn rate of 14.4 means you'll burn through 2% of your monthly budget in a single hour. That's worth waking someone up for. A slow burn that would use up the budget over a few weeks isn't.&lt;/p&gt;

&lt;p&gt;Google's SRE Workbook popularized the multi-window, multi-burn-rate approach. The idea is to alert on a fast burn over a short window, but only if it's been sustained long enough to matter. Here's a simplified version for a 99.9% SLO:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Page: fast burn, sustained over 1h and confirmed over 5m
(
  sum(rate(http_requests_total{status=~"5.."}[1h]))
  / sum(rate(http_requests_total[1h]))
) &amp;gt; (14.4 * 0.001)
and
(
  sum(rate(http_requests_total{status=~"5.."}[5m]))
  / sum(rate(http_requests_total[5m]))
) &amp;gt; (14.4 * 0.001)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The short window stops the alert from firing after the problem is already over. The long window stops it from firing on a 30-second blip. Add a slower tier that opens a ticket instead of paging (something like a burn rate of 1 over three days), and you've covered both the fire and the smoldering pile of trash.&lt;/p&gt;

&lt;p&gt;The important bit: burn-rate alerts go off when users are actually being hurt at a rate that matters. They're very hard to make noisy by accident, because noise means the budget isn't really moving.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. How to Clean Up Without Starting a War
&lt;/h2&gt;

&lt;p&gt;If your current setup is a wall of noise, don't try to fix it in one weekend. You'll break something, and then nobody will trust the new alerts either. Here's what I'd do instead:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Audit the last 30 days of pages.&lt;/strong&gt; For each one, ask: did a human have to do something? If not, demote it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write down the owner and the action for every page.&lt;/strong&gt; If you can't name the action, the alert isn't ready to page anyone.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add an SLO for your most important user journey first.&lt;/strong&gt; Checkout, login, search, whatever pays the bills. One good SLO beats ten vague ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the old alerts running in shadow mode&lt;/strong&gt; for a while so you can compare before you delete them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make it safe to say "this alert is garbage."&lt;/strong&gt; If people get told off for questioning a page, they'll quietly mute it instead. Muting is worse.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Make the Pager Mean Something Again
&lt;/h2&gt;

&lt;p&gt;Your on-call team isn't ignoring 90% of your alerts because they're lazy or careless. They're ignoring them because the alerts stopped meaning anything. Fix that, and the pager starts working again.&lt;/p&gt;

&lt;p&gt;Page on symptoms that hurt users. Use SLOs and burn rates to decide how urgent something is. Send everything else to a dashboard or a ticket queue, where it can be investigated like the interesting-but-not-urgent thing it is. Your engineers will sleep better, and the next time the phone buzzes, they'll actually pick it up.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>sre</category>
      <category>monitoring</category>
      <category>observability</category>
    </item>
    <item>
      <title>Your Container Has No Shell, No curl, and No Mercy</title>
      <dc:creator>nonroot_ops</dc:creator>
      <pubDate>Tue, 24 Nov 2026 20:47:11 +0000</pubDate>
      <link>https://dev.to/nonroot_ops/your-container-has-no-shell-no-curl-and-no-mercy-3231</link>
      <guid>https://dev.to/nonroot_ops/your-container-has-no-shell-no-curl-and-no-mercy-3231</guid>
      <description>&lt;p&gt;It's 3 a.m. The pod is crash-looping. You run &lt;code&gt;kubectl exec -it my-app -- sh&lt;/code&gt; and get back &lt;code&gt;OCI runtime exec failed: exec: "sh": executable file not found in $PATH&lt;/code&gt;. You try &lt;code&gt;curl localhost:8080/health&lt;/code&gt;, and the container just stares back at you. Welcome to distroless.&lt;/p&gt;

&lt;p&gt;If you read &lt;a href="https://dev.to/nonroot_ops/your-docker-image-is-12-gb-for-a-10-mb-app-5f1o"&gt;the last article&lt;/a&gt; and switched your images to distroless, you probably felt pretty smug about it. Smaller image, fewer CVEs, no package manager for attackers to play with. Then the first production incident arrived, and you realized your debugging toolbox was also smaller. Congratulations, you traded convenience for security, and now you have to be cleverer about getting into the box.&lt;/p&gt;

&lt;p&gt;The good news is that you rarely need to get inside the container. You need to get into its namespaces, and Kubernetes gives you a few ways to do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Right Tool: &lt;code&gt;kubectl debug&lt;/code&gt; with an Ephemeral Container
&lt;/h2&gt;

&lt;p&gt;An ephemeral container is a temporary container you attach to a running pod. It doesn't restart the pod, it doesn't touch your main container spec, and it stops when you exit. Ephemeral containers became stable in Kubernetes 1.25, so on any reasonably modern cluster you can use them without feature flags.&lt;/p&gt;

&lt;p&gt;The trick that makes this useful is &lt;code&gt;--target&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl debug -it my-pod --image=busybox:1.36 --target=app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without &lt;code&gt;--target&lt;/code&gt;, your debug container gets its own process namespace, and you can't see what your app is doing. With &lt;code&gt;--target=app&lt;/code&gt;, it shares the process namespace of the &lt;code&gt;app&lt;/code&gt; container. That means you can run &lt;code&gt;ps aux&lt;/code&gt; and see your application's processes. You can also look at &lt;code&gt;/proc/&amp;lt;pid&amp;gt;/fd&lt;/code&gt; to see open file descriptors, or read the environment with &lt;code&gt;/proc/&amp;lt;pid&amp;gt;/environ&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I'll be honest: that last one made me a little uncomfortable the first time I tried it. Environment variables are where secrets tend to live. Anyone who can run &lt;code&gt;kubectl debug&lt;/code&gt; on that pod can read them, so lock down who has that permission through RBAC.&lt;/p&gt;

&lt;p&gt;Also, process namespace sharing depends on your container runtime, so if &lt;code&gt;--target&lt;/code&gt; doesn't behave the way you expect, check that first.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Need Network Tools? Bring the Swiss Army Knife
&lt;/h2&gt;

&lt;p&gt;Busybox is fine for poking at processes, but when the question is "why can't this pod reach the database," you want real networking tools. That's what &lt;code&gt;nicolaka/netshoot&lt;/code&gt; is for. It's a container packed with &lt;code&gt;curl&lt;/code&gt;, &lt;code&gt;dig&lt;/code&gt;, &lt;code&gt;nslookup&lt;/code&gt;, &lt;code&gt;tcpdump&lt;/code&gt;, &lt;code&gt;ss&lt;/code&gt;, &lt;code&gt;ip&lt;/code&gt;, and &lt;code&gt;iperf&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl debug -it my-pod --image=nicolaka/netshoot --target=app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you're inside, the usual checks become easy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;curl -v http://localhost:8080/health&lt;/code&gt; to see whether the app responds at all&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dig my-service.my-namespace.svc.cluster.local&lt;/code&gt; to check DNS&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ss -tlnp&lt;/code&gt; to see what's actually listening&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tcpdump -i any port 5432&lt;/code&gt; when you want to watch packets with your own eyes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because the debug container shares the pod's network namespace, these commands see exactly what your app sees. That's the whole point.&lt;/p&gt;

&lt;p&gt;For Docker outside Kubernetes, you can do the same trick by attaching to the network namespace of a running container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run -it --rm --net container:my-app nicolaka/netshoot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick tip for production: netshoot's tags move around, so pin a digest when you can. The project's own docs recommend &lt;code&gt;nicolaka/netshoot@sha256:...&lt;/code&gt; for debug sessions. A reproducible tool beats a surprise at 3 a.m.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Last Resort: Go Straight to the Node
&lt;/h2&gt;

&lt;p&gt;Sometimes the problem isn't the pod. It's the node, the container runtime, or something that only makes sense from the host's point of view. For that, you can debug the node itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;kubectl debug node/my-node-name -it --image=nicolaka/netshoot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starts a privileged pod that can see the node's namespaces. From there, you can use &lt;code&gt;nsenter&lt;/code&gt; to step into the namespaces of any container running on that node. You first need the container's PID, which you can get from the node's container runtime tooling (for example, &lt;code&gt;crictl ps&lt;/code&gt; and &lt;code&gt;crictl inspect&lt;/code&gt;). Then you enter its network namespace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nsenter -t &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;pid&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; -n ss -tlnp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd treat this as the nuclear option. A privileged pod with host-level access is exactly the kind of thing security teams lose sleep over. Use it when you have to, make sure someone is watching, and delete the debug pod when you're done. Don't leave it running "just in case," because it won't stay small or polite.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. A Quick Decision Guide
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Need to see processes, files, or env vars?&lt;/strong&gt; Use &lt;code&gt;kubectl debug --target&lt;/code&gt; with &lt;code&gt;busybox&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Need to test networking or DNS?&lt;/strong&gt; Use &lt;code&gt;kubectl debug --target&lt;/code&gt; with &lt;code&gt;netshoot&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Need host-level visibility or the container is unreachable?&lt;/strong&gt; Debug the node and use &lt;code&gt;nsenter&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Running plain Docker?&lt;/strong&gt; Use &lt;code&gt;docker run --net container:&amp;lt;name&amp;gt;&lt;/code&gt; with &lt;code&gt;netshoot&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keep the Image Small
&lt;/h2&gt;

&lt;p&gt;Distroless didn't take away your debugging. It just moved it outside the container, where it belongs. Ephemeral containers give you a temporary, targeted view into a running pod, &lt;code&gt;netshoot&lt;/code&gt; gives you the network tools you're used to, and node-level &lt;code&gt;nsenter&lt;/code&gt; covers the cases where none of that is enough.&lt;/p&gt;

&lt;p&gt;And if you're wondering what to do about that missing &lt;code&gt;curl&lt;/code&gt; in your production image, the answer is: keep it out. Let the debug container bring it along when you need it, and leave the image as small as the first article told you to.&lt;/p&gt;

</description>
      <category>kubernetes</category>
      <category>docker</category>
      <category>devops</category>
      <category>linux</category>
    </item>
    <item>
      <title>Your Docker Image Is 1.2 GB for a 10 MB App</title>
      <dc:creator>nonroot_ops</dc:creator>
      <pubDate>Tue, 24 Nov 2026 18:18:34 +0000</pubDate>
      <link>https://dev.to/nonroot_ops/your-docker-image-is-12-gb-for-a-10-mb-app-5f1o</link>
      <guid>https://dev.to/nonroot_ops/your-docker-image-is-12-gb-for-a-10-mb-app-5f1o</guid>
      <description>&lt;p&gt;A team shipped a 200-line service. The Docker image was 1.2 GB. Inside it sat a full Debian install, three package managers, a C compiler, and a &lt;code&gt;.git&lt;/code&gt; folder from 2023. Deploying a hotfix took four minutes, and most of that was just waiting for the image to pull.&lt;/p&gt;

&lt;p&gt;Nobody sets out to build a 1.2 GB image. It usually happens because someone wrote the Dockerfile for their laptop, it worked, and nobody looked at it again. I've done this myself more than once. So let's look at what's actually taking up space, rewrite the Dockerfile, and see how much we can cut.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Find Out What's Eating Your Disk
&lt;/h2&gt;

&lt;p&gt;Don't guess. Start by looking at the image itself. Two tools are handy here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;docker history &amp;lt;image&amp;gt;&lt;/code&gt; lists every layer and how big it is. It's quick and rough, but it usually points you straight at the fat layer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dive&lt;/code&gt; lets you browse the layers interactively and see which files each one added. It's the fastest way to find a stray &lt;code&gt;.git&lt;/code&gt; folder, a package manager cache, or build leftovers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my experience, the biggest layers in a bloated image are almost always the package installs and the &lt;code&gt;COPY . .&lt;/code&gt; that pulled in the whole project. The application code itself is usually tiny by comparison.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. The Dockerfile That Started It All
&lt;/h2&gt;

&lt;p&gt;Here's a realistic example for a Go service:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;FROM&lt;/span&gt; ubuntu:22.04
&lt;span class="k"&gt;RUN&lt;/span&gt; apt-get update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; apt-get install -y golang git gcc python3 python3-pip
&lt;span class="k"&gt;COPY&lt;/span&gt; . /app
&lt;span class="k"&gt;WORKDIR&lt;/span&gt; /app
&lt;span class="k"&gt;RUN&lt;/span&gt; go build -o server .
&lt;span class="k"&gt;CMD&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"./server"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are three problems here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The base image is huge.&lt;/strong&gt; A full Ubuntu install is way more than a small service needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build tools end up in production.&lt;/strong&gt; The compiler, Git, and package managers have no reason to be in a runtime image.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;COPY . /app&lt;/code&gt; grabs everything&lt;/strong&gt;, including &lt;code&gt;.git&lt;/code&gt;, local configs, and that &lt;code&gt;.env&lt;/code&gt; file with the production database password. Yes, that happens more often than anyone admits.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Split the Build from the Runtime
&lt;/h2&gt;

&lt;p&gt;A multi-stage build uses two stages. The first one compiles the code. The second one starts from a clean, minimal image and copies in only the finished binary. The compiler never makes it to production.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Stage 1: build&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; golang:1.25 AS builder
&lt;span class="k"&gt;WORKDIR&lt;/span&gt; /src

&lt;span class="c"&gt;# Copy dependency files first so this layer stays cached&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt; go.mod go.sum ./
&lt;span class="k"&gt;RUN&lt;/span&gt; go mod download

&lt;span class="k"&gt;COPY&lt;/span&gt; . .
&lt;span class="k"&gt;RUN&lt;/span&gt; &lt;span class="nv"&gt;CGO_ENABLED&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 &lt;span class="nv"&gt;GOOS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;linux go build -o /out/server .

&lt;span class="c"&gt;# Stage 2: runtime&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; gcr.io/distroless/static-debian12:nonroot
&lt;span class="k"&gt;COPY&lt;/span&gt; --from=builder /out/server /server
&lt;span class="k"&gt;EXPOSE&lt;/span&gt; 8080
&lt;span class="k"&gt;ENTRYPOINT&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"/server"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things worth noticing:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Order matters.&lt;/strong&gt; Copying &lt;code&gt;go.mod&lt;/code&gt; and &lt;code&gt;go.sum&lt;/code&gt; before the source means Docker only re-downloads dependencies when they actually change. Without this, every typo fix triggers a full dependency download.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;CGO_ENABLED=0&lt;/code&gt;&lt;/strong&gt; gives you a statically linked binary that doesn't need system libraries. That's what makes a tiny base image possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;:nonroot&lt;/code&gt;&lt;/strong&gt; runs the process without root. It's not a silver bullet, but it's a free security win.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, add a &lt;code&gt;.dockerignore&lt;/code&gt; so junk never reaches the build context in the first place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.git
.gitignore
Dockerfile
.dockerignore
*.md
bin/
tmp/
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'd argue &lt;code&gt;.dockerignore&lt;/code&gt; matters more for security than for size. Keeping secrets out of the image is a much bigger deal than saving a few megabytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A note for Python folks:&lt;/strong&gt; the same idea applies. Install your dependencies in a build stage with a full Python image, then copy only the result (a virtual environment or a dedicated &lt;code&gt;site-packages&lt;/code&gt; directory) into a slim runtime image. Add &lt;code&gt;--no-cache-dir&lt;/code&gt; to &lt;code&gt;pip install&lt;/code&gt; so pip's cache doesn't get baked into a layer. And chain related &lt;code&gt;RUN&lt;/code&gt; commands together, because deleting a file in a later layer doesn't remove it from the earlier layer. It's still in the image, just hidden.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Choosing the Base Image
&lt;/h2&gt;

&lt;p&gt;The base of your final stage makes the biggest difference to size. Here's how I'd think about it:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Base image&lt;/th&gt;
&lt;th&gt;When it fits&lt;/th&gt;
&lt;th&gt;Things to know&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;scratch&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A static binary that needs nothing else&lt;/td&gt;
&lt;td&gt;Completely empty. No shell, no CA certificates.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;distroless/static&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A static binary that needs CA certs and timezone data&lt;/td&gt;
&lt;td&gt;My default for Go and Rust services.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;distroless/base&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A dynamically linked binary that needs glibc&lt;/td&gt;
&lt;td&gt;Good for C/C++, or Python with native extensions.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;alpine&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A general-purpose small base&lt;/td&gt;
&lt;td&gt;Uses musl instead of glibc. That can cause subtle bugs, and some Python wheels end up compiling from source.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Alpine gets recommended constantly, but it isn't always the right answer. Distroless or slim images usually get you most of the savings without swapping out your C library, which saves you from a whole category of weird bugs.&lt;/p&gt;

&lt;p&gt;On security: fewer packages means fewer CVEs to track and patch. Distroless images also ship without a shell or a package manager, so if an attacker gets in, they have far fewer tools to work with. The downside is that you can't just &lt;code&gt;docker exec -it container sh&lt;/code&gt; to poke around when something breaks. Google publishes a &lt;code&gt;:debug&lt;/code&gt; variant for that, but please don't ship it to production.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Before and After
&lt;/h2&gt;

&lt;p&gt;These numbers are illustrative, based on a typical Go service. Your results will vary with your app and your dependencies, so measure your own images with &lt;code&gt;docker images&lt;/code&gt; and &lt;code&gt;docker history&lt;/code&gt; before you believe any table, including mine.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Before (Ubuntu + tools)&lt;/th&gt;
&lt;th&gt;After (multi-stage + distroless)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Image size&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~1.2 GB&lt;/td&gt;
&lt;td&gt;~15–20 MB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Base layer&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~80 MB Ubuntu + tools&lt;/td&gt;
&lt;td&gt;~2 MB &lt;code&gt;distroless/static&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Build time (no cache)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;several minutes&lt;/td&gt;
&lt;td&gt;under a minute, roughly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Pull time at 100 Mb/s&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;~1.5 minutes before overhead&lt;/td&gt;
&lt;td&gt;a second or two&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Packages in the image&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;hundreds&lt;/td&gt;
&lt;td&gt;almost none (just CA certs and tzdata)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The pull math: 1.2 GB is about 9,600 megabits. At 100 Mb/s, that's around 96 seconds before registry overhead, so the real number is a bit higher. A 15 MB image transfers almost instantly. That gap is the difference between a hotfix that sits in a queue for four minutes and one that's live before your coffee gets cold.&lt;/p&gt;

&lt;p&gt;For a statically compiled binary, 10 to 20 MB is a realistic target.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Short Version
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Measure before you optimize. &lt;code&gt;docker history&lt;/code&gt; and &lt;code&gt;dive&lt;/code&gt; will show you the real culprits.&lt;/li&gt;
&lt;li&gt;Separate build from runtime with a multi-stage build.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;.dockerignore&lt;/code&gt; to keep &lt;code&gt;.git&lt;/code&gt;, secrets, and temp files out of the image.&lt;/li&gt;
&lt;li&gt;Pick the smallest base your app can actually run on.&lt;/li&gt;
&lt;li&gt;Run as non-root whenever you can.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You end up with a smaller image, faster deploys, and less to defend. And the team from the intro gets its four minutes back on every hotfix.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>devops</category>
      <category>go</category>
      <category>security</category>
    </item>
  </channel>
</rss>
