# My Node.js Docker image is over a gigabyte, how do I make it smaller?

Source: https://gitshowcase.com/forum/discuss/my-nodejs-docker-image-is-over-a-gigabyte-how-do-i-make-it-smaller/
Site: GitShowcase Forum, category Hosting, Edge and Deploys
Published: 2026-12-04. Updated: 2026-12-04. Replies: 2.

## Question by Kwesi A., 2026-12-04

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.

This is my whole Dockerfile:

```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.

## Reply 1 by Teodor M., 2026-12-04

Start with a `.dockerignore`. `COPY . .` takes your local `node_modules`, `.git`, build output and probably an `.env` into the image, and the local `node_modules` may even overwrite the one `npm install` just made. Ignore them all before touching anything else.

## Reply 2 by Imani H., 2026-12-04

I think you can just add `RUN npm prune --production` and `RUN rm -rf` the dev stuff at the end of the Dockerfile and it gets smaller? That is what a tutorial showed me.

---
Cite as: 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.
