Your clarification in the comment on @Kuhess's answer, which says that the actual problem is βthe invalidation of the docker image cache, resulting in the installation of the package starting againβ, is useful to provide you with an answer.
I am using a Dockerfile which looks like this for my rails 4.1. * app. First, ADDing Gemfile *, then starting the package installation and only then adding the rest of the application, the package installation step will be cached if one of the Gemfile * files is not changed.
FROM ruby:2.1.3 RUN adduser --disabled-password --home=/rails --gecos "" rails RUN gem install bundler --no-ri --no-rdoc RUN gem install -f rake --no-ri --no-rdoc RUN mkdir /myapp WORKDIR /myapp ADD Gemfile /myapp/Gemfile ADD Gemfile.lock /myapp/Gemfile.lock RUN bundle install ADD . /myapp RUN chown -R rails:rails /myapp USER rails EXPOSE 3000 ENV RAILS_ENV production CMD bundle exec rails server -p 3000
My Dockerfile is located in the root directory of the application, but changes in it (or any other part of the application) do not break the image cache for installing the package, because they are added after they are launched. The only thing that violates it is the changes to the Gemfile *, which is true.
FYI, my .dockerignore file looks like this:
.git log vendor/bundle
source share