简体   繁体   中英

“Problems” creating an image with Docker

I have a somewhat peculiar situation involving Docker and Ruby on Rails.

I'm creating images of a Ruby on Rails project, the problem would be that the images are getting too big.

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

Using smaller official Ruby images like Slim-Buster and Alpine, the images created by me were not so small, reaching approximately 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".

The /usr directory is the biggest "underdog" after running the bundle install.

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. Even so, the message "Install missing gem executables with bundle install " is reported after attempting to execute the" bundle exec puma "command.

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.

Answers could be much more helpful if you post your Dockerfile :)

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