Each line is cached, so if I only use COPY . /my-api I will have to run bundler every time anything in my code changes, which takes time and would be annoying.
By copying over the gemfiles first and running bundler those packages are cached and rebuilds will be faster. As docker-compose is smart enough to realize those files didn't change so it will skip the gemfile and bundler steps when building.
It wouldn't change the need to rebuild and rerun bundler if the gemfiles changed. I always prefer to rebuild the container when updating gemfiles. I don't want my docker-compose file to get out of sync with what happens in my container.
Each line is cached, so if I only use
COPY . /my-api
I will have to run bundler every time anything in my code changes, which takes time and would be annoying.By copying over the gemfiles first and running bundler those packages are cached and rebuilds will be faster. As docker-compose is smart enough to realize those files didn't change so it will skip the gemfile and bundler steps when building.
You could instead use a volume in docker-compose
It wouldn't change the need to rebuild and rerun bundler if the gemfiles changed. I always prefer to rebuild the container when updating gemfiles. I don't want my docker-compose file to get out of sync with what happens in my container.
Ahh. That makes sense. Thanks for clearing things up for me 😁