Live data from Hacker News

We reduced a container image from 800GB to 2GB

sealos.io

41–50 of 88 posts

Re: We reduced a container image from 800GB to 2GB

#41
What's up with the images that are supposed to appear in the article? They appear to be coded to load from "./images/containerd-high-disk-io-iotop.png", but https://sealos.io/blog/images/containerd-high-disk-io-iotop.... and https://sealos.io/images/containerd-high-disk-io-iotop.png both fail.

(And indeed, the images are broken in Firefox and Edge. Is there another browser where they're not broken?)

Re: We reduced a container image from 800GB to 2GB

#42
post #27

272 layers in a single image seems really unusual, is that just due to my lack of experience with containers? I've never seen an image with more than maybe a few dozen in my career...

Well, as described...

> Here's how the disaster unfolded:

> 1. A user's container is under a brute-force attack, and /var/log/btmp grows to 11GB.

> 2. The user performs a commit, creating a new image layer.

> 3. A single new failed login is appended to /var/log/btmp.

> 4. Because of CoW, OverlayFS doesn't just write the new line. It copies the entire 11GB file into the new, upper layer.

> 5. This process repeated 271 times.

So the user is creating hundreds of layers for unclear reasons. The article refers to this as "exponential growth", but for that to be the case those commits would need to be triggered in proportion to the number of existing layers, which seems unlikely. Assuming the commits are caused by the user for reasons unrelated to the size of the existing image, this is growth that is quadratic† (in the number of layers; it's hard to characterize as a function of time or whatever), and it'd be nice to know why there were so many layers.

† Note that while the growth is technically quadratic, I don't think that impacted them. They say that the problem occurred when one 11GB file got copied into each of 272 image layers. That would require 2,992 GB, but they also say that the image exhibiting this problem was only 800GB.

I suspect that the answer here is that only some of the layers modified (and therefore copied) the log file. Probably about 72 of the layers. This is more like growth that's linear (still technically slightly superlinear, but probably not quadratic) in the number of failed SSH login attempts. ~75% of layers aren't contributing to the problem at all.

Re: We reduced a container image from 800GB to 2GB

#43
post #21

Fascinating deep dive into OverlayFS CoW behavior. The 11GB btmp file getting copied 271 times is a perfect storm scenario. Did they consider mounting /var/log outside the image layers? Seems like that would prevent any log file from causing this amplification. Also interested in image-manip... Does it handle metadata differently than docker export/import?

Is it fascinating? Do people not know that each layer comes with its own downsides? Do people just do 272 layers and think that it’s normal? This seems like people discovering that water is wet and fire is hot.

I feel like I'm having a LLM fever dream

Re: We reduced a container image from 800GB to 2GB

#44

Interesting, although something about the language makes me think it was written by a LLM; I like the ending though: "The key insight is to treat container images not as opaque black boxes, but as structured, manipulable archives. Deeply understanding the underlying technology, like the OCI image specification, allows for advanced optimization and troubleshooting that goes far beyond standard tooling. This knowledge…

Not a guaranteed tell but I noticed the word "surgically" in the opening paragraphs, and from personal experience I find that appears in ChatGPT a lot for me. One of the common phrase tropes I find is something like "Here's a set of small, surgical steps you can take to..."

Yeah, but just also the overall feel of the article is kind of LLM-y and not human in some hard to articulate way

Re: We reduced a container image from 800GB to 2GB

#45
post #28

I’m shocked that a company would share how amazingly bad their layer management had become. This may be a great internal blog, but I wouldn’t share it publicly.

On the other hand, I'm impressed that a company is owning up to the problem. Is it a dumb problem to have? Definitely. Are they the only ones to have it? Almost certainly not. People are going to use the tools at their disposal, and they aren't all going to learn their tools at a high level. Think of every insane misuse of Excel you've ever heard of, for instance. IT has the choice in this case to mitigate, or limit…

Yeah: I can usually tell from public information when a company has problems like this, and that makes me disinclined to want to work for them. Seeing how they deal with those problems, though? … Well, in this case, it shows that the company doesn't know how to deal with these problems properly, and thinks ChatGPT is appropriate for write-ups, so I still might not want to work there – but I might bother interviewing there, just to check how deep these problems go. (If they're just a case of "they didn't know better, but they're happy to learn", then I might actually take the job offer: an environment where others are willing to learn without fear of losing face is an environment where I can learn without worrying about that either.)

Re: We reduced a container image from 800GB to 2GB

#46
post #27

272 layers in a single image seems really unusual, is that just due to my lack of experience with containers? I've never seen an image with more than maybe a few dozen in my career...

You can build docker images with nix, in which case you can have every dependency be its own layer.

That is clearly not what these people are doing, though.

Re: We reduced a container image from 800GB to 2GB

#47
post #28

I’m shocked that a company would share how amazingly bad their layer management had become. This may be a great internal blog, but I wouldn’t share it publicly.

I'm confused. I had the same initial reaction as you and then read further and it sounds like the image was actually provided by a client?

    > The problematic user image had an astonishing 272 layers, each representing a commit operation.

Re: We reduced a container image from 800GB to 2GB

#48

Our platform is designed to solve a very specific workflow, and the DevBox is only the first step in that process. Our users need to connect their local VS Code, Cursor, or JetBrains IDEs to the cloud environment. The industry-standard extensions for this only speak the SSH protocol. So, to give our users the tools they love, the container must run an SSHD to act as the host. We aren't just a CDE like Coder or Codesp…

The irony is that Kubernetes already provides a "ssh into any container" ability, and it's provided directly by k8s, no sshd needed (it's not the ssh protocol but it's good enough to get a shell). Not sure it's advisable to do with any user but an admin, but the standard workflow with k8s is not to shell into running containers anyway, it's to rebuild the container and redeploy the pod.

Re: We reduced a container image from 800GB to 2GB

#49

The real lesson they should learn is to not rely on running images and then using "docker commit" to turn it into an image, but instead to use proper image building tools. If you absolutely have to do it that way, be very deliberate about what you actually need. Don't run an SSH daemon, don't run cron, don't an SMTP daemon, don't run the suite of daemons that run on a typical Linux server. Only run precisely what you…

My first reaction: 800GB who committed that?!? This size alone screams something is wrong. To be fair even with basic dockerfiles it’s easy to build up a lot of junk. But there should be a general size limit in any workflow that just alerts when something grows out of proportion. We had this in our shop just a few weeks ago. A docker image for some ai training etc grew too big and nobody got alerted about the image final size. It got committed and pushed to jfrog. From there the image synced to a lot of machines. Jfrog informed us that something is off with our amount of data we shuffle around. So on one end this should not happen but it seems to easily end up in production without warning.

Re: We reduced a container image from 800GB to 2GB

#50

TIL of `docker commit`. What is the use case for this command? Quick debugging or something, to share with a coworker?

Same as snapshotting a vm, or as an interactive version of "docker build". But rarely useful, since most workflows don't really need statefulness.

It seems like their whole platform depends on it though… to my read they’re providing their users with cloud devcontainers to connect to from their local VS Code, then deploying to production by snapshotting the container with docker commit. Those containers have SSH enabled to the internet, which is where all of the auth logs came from that wound up baked into the images.
Post reply on HN