In Dockerfile, dependency files are often first copied (gemfile / package.json, etc.), and then dependencies are installed. Then the entire application is copied.
Why is it not recommended to just copy the whole folder and install the dependencies?
In Dockerfile, dependency files are often first copied (gemfile / package.json, etc.), and then dependencies are installed. Then the entire application is copied.
Why is it not recommended to just copy the whole folder and install the dependencies?
Good day.
I occasionally have to "pack" rails-applications in docker-images and noted some points for myself.
Answering the question:
Why is it not recommended to just copy the whole folder and install the dependencies?
I suppose, because the assembly of the image will not be as fast as it could be.
Suppose that after building a docker image with your application, you need to continue to refine this application and test its operation in the image.
If your Dockerfile has something like:
... COPY . /app/folder RUN bundle install then at each update of any file, docker will copy files and install dependencies again. It takes a lot of time.
And if you write like this:
COPY Gemfile* /app/folder RUN bundle install ... COPY . /app/folder then dependencies will be conditionally already “installed” and the image will be assembled faster.
You can still speed up image building by bundling rails application dependencies.
bundle package The gems will be placed in the / vendor / cache directory and in Dockerfile you can then write this:
COPY Gemfile* /app/folder COPY vendor/cache ./vendor/cache RUN bundle install --local ... COPY . /app/folder With frequent modifications of the project, such a configuration, in my opinion, can significantly reduce the time to build images.
Source: https://ru.stackoverflow.com/questions/843063/
All Articles