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.

1
2
3
4
COPY --from=docker-repo.link/image:latest /app/node_modules /app/node_modules
COPY --from=docker-repo.link/image:latest /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.