简体   繁体   中英

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM