I hope this doesn't sound stupid but why didn't we just do
COPY . /my-api
RUN bundle install
instead of the longer version
COPY Gemfile /my-api/Gemfile
COPY Gemfile.lock /my-api/Gemfile.lock
Copying the Gemfiles to the working space in the container.
RUN bundle install
This will run bundler in the container.
COPY . /my-api
Copy all the other files into the working space.
Jenn is a self taught web developer who specializes in usability and accessibility. She is easily spotted at conferences by her bright lipstick and various code dresses and t-shirts.
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.
Jenn is a self taught web developer who specializes in usability and accessibility. She is easily spotted at conferences by her bright lipstick and various code dresses and t-shirts.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I hope this doesn't sound stupid but why didn't we just do
instead of the longer version
Is there a huge difference between the two?
Great article btw!
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.
Ahh. That makes sense. Thanks for clearing things up for me 😁
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.