Why would you copy your Gemfile.lock into Docker, then immediately overwrite it?

More a guess than an answer, but sometimes you order the steps in Dockerfiles slightly differently to improve the caching mechanism. When you change things in your application, it's less likely that it will affect the Gemfiles, so you don't have to do a bundle install after everything you change. Ordering the steps in this way avoids having to execute bundle install for changes to your application that do not affect the Gemfiles.

Documentation on build caching: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#build-cache