有什么方法可以优化 Docker 图片的大小吗?
Is there any way to optimize size of Docker Image?
我在本地使用 V10 Angular 应用程序 运行。我正在尝试在 Dockerfile.But 的帮助下构建一个 Docker 图像,同时构建图像,我的 Docker 图像大小正在构建为 1.32GB。有什么办法可以减小它的大小吗?
下面是我写的Docker文件
# base image
FROM node:12.2.0
# set working directory (also creates two folders needed for cypress)
RUN mkdir /usr/src/app && mkdir /usr/src/app/cypress && mkdir /usr/src/app/cypress/plugins
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install app and cache app dependencies
COPY . /usr/src/app
RUN npm install --silent
EXPOSE 4200
# start app
CMD ["npm", "run", "ng serve"]
请注意:- 在本地,根文件夹显示 属性 为 1,14,774 项,总计 1.3 GB。
你的 base image uncompressed size is 906MB. I would advice you to try with the slim version 是 150MB。
# base image
FROM node:12.2.0-slim
# set working directory (also creates two folders needed for cypress)
RUN mkdir /usr/src/app && mkdir /usr/src/app/cypress && mkdir /usr/src/app/cypress/plugins
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install app and cache app dependencies
COPY . /usr/src/app
RUN npm install --silent
EXPOSE 4200
# start app
CMD ["npm", "run", "ng serve"]
还有更小的 alpine version (77.7MB)。
我通过在创建图像时不复制 node_modules 文件夹解决了这个问题。所以我所做的就是从 github 中克隆 node_modules 文件夹本身不可用并创建图像。之后总大小变为只有 14.48 MB。因此,删除 node_modules 解决了我的问题。
我在本地使用 V10 Angular 应用程序 运行。我正在尝试在 Dockerfile.But 的帮助下构建一个 Docker 图像,同时构建图像,我的 Docker 图像大小正在构建为 1.32GB。有什么办法可以减小它的大小吗?
下面是我写的Docker文件
# base image
FROM node:12.2.0
# set working directory (also creates two folders needed for cypress)
RUN mkdir /usr/src/app && mkdir /usr/src/app/cypress && mkdir /usr/src/app/cypress/plugins
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install app and cache app dependencies
COPY . /usr/src/app
RUN npm install --silent
EXPOSE 4200
# start app
CMD ["npm", "run", "ng serve"]
请注意:- 在本地,根文件夹显示 属性 为 1,14,774 项,总计 1.3 GB。
你的 base image uncompressed size is 906MB. I would advice you to try with the slim version 是 150MB。
# base image
FROM node:12.2.0-slim
# set working directory (also creates two folders needed for cypress)
RUN mkdir /usr/src/app && mkdir /usr/src/app/cypress && mkdir /usr/src/app/cypress/plugins
WORKDIR /usr/src/app
# add `/usr/src/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH
# install app and cache app dependencies
COPY . /usr/src/app
RUN npm install --silent
EXPOSE 4200
# start app
CMD ["npm", "run", "ng serve"]
还有更小的 alpine version (77.7MB)。
我通过在创建图像时不复制 node_modules 文件夹解决了这个问题。所以我所做的就是从 github 中克隆 node_modules 文件夹本身不可用并创建图像。之后总大小变为只有 14.48 MB。因此,删除 node_modules 解决了我的问题。