Caching Issue 2: Unnecessary Gem Installs

Imagine that we want to make a change to our README.md file. Open this file in an editor, and replace the Rails default version with the following:

 # README
 
 This is a sample Rails application from Docker for Rails Developers (PragProg).
 It was generated using Docker without Ruby installed on the local machine.
 
 We're using the app to discover the wonderful world of Rails with Docker.

Now let’s try something. What happens if we rebuild our image:

 $ ​​docker​​ ​​build​​ ​​-t​​ ​​railsapp​​ ​​.
 Sending build context to Docker daemon 102.9kB
 Step 1/6 : FROM ruby:2.6
  --->​​ ​​f28a9e1d0449
 Step 2/6 : RUN apt-get update -yqq && apt-get install -yqq --no-install-
 recommends nodejs
  --->

Get Docker for Rails Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.