AWS Builder Center

The Day My Docker Image Grew to 8GB — And Took Down Our Deploy Pipeline

A missing .dockerignore file let Docker copy node_modules, build output, and a forgotten 1.4GB backup folder into a small Node API's container. The bloated image blew our registry quota and blocked every deploy for an afternoon — here's the four-minute fix and the pipeline size check that now stops it before it ships.

The deploy had been running for fourteen minutes when Slack lit up.
Not with a success message. With a red X and the kind of error text that makes you reread it three times because it feels personally insulting:  push access denied: registry storage quota exceeded .
I checked the image size. 8.1GB.
Our registry quota was 10GB. We had two other services in there. I had eaten almost all of it with one container.
The worst part? The app was a small Node API. It had no business being bigger than a few hundred megabytes.
I opened the Dockerfile. Nothing weird. A standard  node:18-alpine  base, a  COPY package*.json , an  npm ci , then this line:
COPY . .
That line was the whole problem. Not because  COPY . .  is evil. Because I had never created a  .dockerignore  file. So Docker did exactly what I told it to do: it copied everything sitting in my project folder.
Everything.
 node_modules  from three different local installs. A  dist  folder from last week. Coverage reports. A  .git  directory. Some stray logs from a debugging session in March. And a 1.4GB folder called  backup-test  that I honestly do not remember creating.
Docker baked all of it into the image. Then our CI pushed that 8.1GB thing to the registry, hit the quota, and failed at the push step. The deploy job sat at 94% for eleven minutes before it gave up.
Nobody could deploy anything for the rest of the afternoon. Not because the code was broken. Because I had accidentally uploaded my entire working directory to production infrastructure.
The fix took four minutes. I added a  .dockerignore :
node_modules
dist
coverage
.git
*.log
backup-test
.env
Rebuilt. The image came out at 187MB. It pushed in under a minute. Deploy went green. I closed my laptop and sat there for a while.
But a  .dockerignore  alone is not a guardrail. It is a good habit. Habits get skipped when someone is in a hurry. So I added a step to the pipeline that checks the image size before the push. If it is over 500MB, the job fails with a message that says, plainly: “Image size exceeded. Check .dockerignore.”
That step has not fired since.
But it will. Someone on the team will add a folder, forget the ignore file, and try to ship a container full of junk. The pipeline will stop them before the registry does.
The lesson was not “write a  .dockerignore .” I knew that. I had just assumed I did not need one because the project felt small. Small projects still carry old build folders, local dependencies, and whatever  backup-test  was.
Docker does not know what matters. It copies what you give it. Turns out I was giving it a lot more than I thought.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article