The slowest step (in my experience and opinion) is compiling assets (js/css). Compiling assets takes time and slower when you do it for the first time. So to speed it up its recommended to copy the last compiled assets from the latest image you have of the repo.

COPY /app/node_modules /app/node_modules
COPY /app/public /app/public

RUN bundle exec rails assets:precompile

Now since the prior assets are in the new image, it won’t compile the assets from scratch and the build will be faster.