My Node.js Docker image is over a gigabyte, how do I make it smaller?
I am containerising a client's Express and TypeScript API for the first time. It works, but docker image ls shows the image is over a gigabyte, and pushing it to the registry from my slow connection takes ages. The client's host also bills for registry storage, so I would like it lean.
Cite
GitShowcase Forum, "My Node.js Docker image is over a gigabyte, how do I make it smaller?", https://gitshowcase.com/forum/discuss/my-nodejs-docker-image-is-over-a-gigabyte-how-do-i-make-it-smaller/, accessed 2026-12-05.This is my whole Dockerfile:
FROM node:22 WORKDIR /app COPY . . RUN npm install RUN npm run build CMD ["node", "dist/server.js"]There is no
.dockerignore. The project has about 40 dependencies and a dozen dev dependencies (TypeScript, ESLint, test tooling).What are the biggest wins, in order? I have read about multi-stage builds and Alpine images but I do not know which matters more, and I am worried that a smaller base image will break things I cannot see yet. I would also like to know what should never end up inside the image, since I copy the whole folder right now.
Write something first.
Give people something to work with: at least 30 words on what happened and what you tried.
That is too long. Keep it under 6,000 characters.
Write the question as the title, 15 to 140 characters, no links.
Pick a category.
Add a name (2 to 40 characters, no links).
That email address does not look right.
That was quick. Read the thread, then try again.
The form expired. Reload the page and post again.
Something went wrong with the form. Reload and try again.
Please complete the check and post again.
Limit reached for now. Try again later.
This thread is closed to new replies.
This thread no longer accepts replies.
Something went wrong with the form. Reload and try again.
Post a reply or question first (name and email), then this browser can vote, edit and accept answers.
You cannot vote on your own post.
Only the author (within 30 days) or the forum team can do that.
That email already has an account. Use your sign-in link instead.
New accounts are paused for the moment. Try again later.
That was already posted.