简体   繁体   English

使用 Docker 创建映像的“问题”

[英]“Problems” creating an image with Docker

I have a somewhat peculiar situation involving Docker and Ruby on Rails.我有一个有点特殊的情况,涉及 Rails 上的 Docker 和 Ruby。

I'm creating images of a Ruby on Rails project, the problem would be that the images are getting too big.我正在创建 Ruby on Rails 项目的图像,问题是图像变得太大。

The project in question is a monolith that will become a microservice.有问题的项目是一个将成为微服务的单体。

I intend to use the images in a Kubernetes cluster and due to the size of the images this can be detrimental to the K8S and the deployment time我打算在 Kubernetes 集群中使用图像,由于图像的大小,这可能不利于 K8S 和部署时间

Using smaller official Ruby images like Slim-Buster and Alpine, the images created by me were not so small, reaching approximately 600MB.使用像 Slim-Buster 和 Alpine 这样更小的官方 Ruby 镜像,我创建的镜像并没有那么小,达到大约 600MB。

The main reason is due to the mandatory execution of the bundle install command.主要原因是捆绑安装命令的强制执行。

To execute the "bundle exec puma" command, it first requests the execution of the "bundle install".为了执行“bundle exec puma”命令,它首先请求执行“bundle install”。

The /usr directory is the biggest "underdog" after running the bundle install. /usr 目录是运行捆绑安装后最大的“失败者”。

I tried to get around this situation by placing the /usr directory with the Gems already installed on my local host and then mounting it in the container.我试图通过将已安装 Gems 的 /usr 目录放置在我的本地主机上,然后将其挂载到容器中来解决这种情况。 Even so, the message "Install missing gem executables with bundle install " is reported after attempting to execute the" bundle exec puma "command.即便如此,在尝试执行“bundle exec puma”命令后仍会报告消息“使用bundle install安装缺少的 gem 可执行文件”。

Could you give me any tips on how to get around this situation with this project?你能给我一些关于如何通过这个项目解决这种情况的提示吗?

I'm avoiding reformulating the whole project to be migrated to microservices at this point, but I need some advice.在这一点上,我正在避免重新制定要迁移到微服务的整个项目,但我需要一些建议。

Thank you very much in advance非常感谢您提前

The most obvious advice would be to remove the unnecessary folders like spec (if you don't run tests over your docker image), node_modules and app/assets because you don't need them in production since they are normally precompiled.最明显的建议是删除不必要的文件夹,例如spec (如果您不对 docker 映像运行测试)、 node_modulesapp/assets ,因为您在生产中不需要它们,因为它们通常是预编译的。

Answers could be much more helpful if you post your Dockerfile :)如果您发布Dockerfile ,答案可能会更有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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