trying2dev
trying2dev

Reputation: 51

How to use multistage build on node docker file

I am using this docker file to give a simple hello world output on the browser. The docker file copies in the package.json(which already has express defined on it) and the index.json(which uses the express framework to display hello world)

Currently the size of this image is around 900Mb, I do want to make it smaller. I have tried multi-stage build , but im quite new to docker so don't really know how to.

FROM node:latest
WORKDIR /app
COPY package.json index.j ./
RUN npm install
EXPOSE 8080
CMD node index.js

As currently this is a very big docker file, how can I reduce the size using multi-stage?

Upvotes: 3

Views: 1294

Answers (2)

udara vimukthi
udara vimukthi

Reputation: 166

Try to work with a virtual machine that solving many issues with the size issues of docker images, which pull from the docker hub. After that, you can work very fast with docker hub images, otherwise, the size of docker hub images which pull may be a big issue for you.

Upvotes: 1

Mustafa Güler
Mustafa Güler

Reputation: 1014

Try to use node:slim (160 MB) image not latest (960 MB) which has common packages inside.

Upvotes: 3

Related Questions