英文:
How to Optimize Docker Image Size and Reduce Push Time to Harbor?
问题
我目前在我的公司中使用Harbor作为Docker镜像配置管理工具。在在Linux服务器上运行Next.js Docker镜像之前,我会将Docker镜像推送到Harbor,然后在服务器上执行它。
然而,我面临一个问题,即Next.js Docker镜像中的node_modules文件大小和Docker镜像的总体大小都很大。结果,将镜像推送到Harbor需要很长时间,平均超过8分钟。
为了减小镜像大小,我已尝试减少运行步骤并使用技巧来优化项目,比如使用构建器,运行 'npm install --production',以及删除 '.next/cache' 目录。然而,这些努力并没有显著解决问题。
团队坚持要减小镜像大小,因为构建时间很长。然而,根据我的当前知识,我认为这个优化水平已经是我能达到的最好水平了。
如果有人遇到类似的问题,我会非常感谢他们提供的任何提示或解决方法。
谢谢。
附言:我不擅长英语,所以我将其翻译成了gpt。可能存在不正确的语法。
我想加快镜像构建速度并缩短推送到Harbor的时间。
英文:
I am currently using Harbor as a Docker image configuration management tool in my company. Before running the Next.js Docker image on the Linux server, I push the Docker image to Harbor and then execute it on the server.
However, I am facing a problem where both the size of the node_modules file in the Next.js Docker image and the overall size of the Docker image are large. As a result, it takes a long time to push the image to Harbor, averaging more than 8 minutes.
To reduce the image size, I have tried reducing the running steps and optimizing the project using techniques like using a builder, running 'npm install --production', and removing the '.next/cache' directory. However, these efforts have not significantly resolved the issue.
The team keeps insisting on reducing the image size due to the lengthy build time. However, based on my current knowledge, I believe that this level of optimization is the best I can achieve.
If anyone has encountered a similar problem, I would appreciate any hints or workarounds they can provide.
Thank you.
ps: I don't speak English well, so I translated it to gpt. There may be incorrect grammar.
I want to speed up image builds and reduce time to push to harbor.
答案1
得分: 1
以下是要翻译的内容:
这是您需要执行的5个步骤:
- 使用最小的基础映像(阅读
https://snyk.io/blog/choosing-the-best-node-js-docker-image/
) - 您应该使用多阶段构建(multistage builds)
- 使用 .Dockerignore
- 仔细检查依赖项
- 使镜像层尽可能小
您绝对应该尝试使用 Dive(https://github.com/wagoodman/dive),它用于探索 Docker 镜像、层内容,并发现缩小 Docker/OCI 镜像大小的方法。
在检查了这些步骤后,无论您使用 Harbor 还是其他任何镜像仓库都不重要。
英文:
These are 5 steps you need to perform:
- use minimal base images(read
https://snyk.io/blog/choosing-the-best-node-js-docker-image/
) - you should use multistagebuilds
- use .Dockerignore
- Double-check the dependencies
- Make image layer as small as possible
You should definetly try Dive(https://github.com/wagoodman/dive),which serves for exploring a docker image, layer contents, and discovering ways to shrink the size of your Docker/OCI image.
After checking these steps it does not matter if your are using Harbor or any other image repository.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论