Docker Cache BUNDLE INSTALL not working

Anybody knows how to make BUNDLE INSTALL Cache’ing work in latest DOCKER release?
I’ve tried so far:

1. 
WORKDIR /tmp 
ADD ./Gemfile Gemfile
ADD ./Gemfile.lock Gemfile.lock
RUN bundle install

2.
ADD . opt/railsapp/
WORKIDR opt/rails/app
RUN bundle install

None of them work, it still runs “BUNDE INSTALL” everytime from scratch without Gemfile being changed.

  • how to create docker image from an ISO file?
  • How to restrict cpu usage from host to docker container
  • Deploy Angular2 with Router inside a Docker Container using Nginx
  • How can I reset a Dockerized Rails app for integration testing?
  • Would using Docker (Docker Swarm) grant any additional benefits when making an N node Raspberry Pi cluster web server?
  • ssh into boot2docker - can you see -v folders from within boot2docker vm
  • Anyone knows how to make Caching for bundle install work correctly?

    Cheers,
    Andrew

  • Connecting webpack-dev-server inside a Docker container from the host
  • If an marathon app running in a docker image, is in 'deploying' state, where can we check the reason why the app isn't deploying?
  • netcat udp connection hang inside UDP conatiner
  • Remote access to webserver in docker container
  • How to restore postgres within a docker?
  • How to run *BSD OS on Docker?
  • 3 Solutions collect form web for “Docker Cache BUNDLE INSTALL not working”

    Each time you change any file in your local app directory, the cache will be wiped out, forcing every step afterwards to be re-run, including the last bundle install.

    The solution is don’t run bundle install in step 2. You have already installed your gems in step 1 and there is little chance the Gemfile will change between step 1 and step 2 ;-).

    The whole point of step 1 is to add your Gemfile, which should not change to often, so you can cache it and the subsequent bundle command before adding the rest of your app, which will probably change very often if you are still developing it.

    Here’s how the Dockerfile could look like:

    1. 
    WORKDIR /tmp 
    ADD ./Gemfile Gemfile
    ADD ./Gemfile.lock Gemfile.lock
    RUN bundle install
    
    2.
    ADD . opt/railsapp/
    WORKIDR opt/rails/app
    

    Versions of Docker before 0.9.1 did not cache ADD instructions. Can you check that you’re running a version of Docker 0.9.1 or greater?

    Also, which installation of Docker are you using? According to this GitHub issue, some users have experienced cache-busting ADD behavior when using unsupported Docker builds. Make sure you’re using an official Docker build.

    ADD caching is based on all the metadata of the file, not just the contents.

    if you are running docker build in a CI-like environment with a fresh checkout, then it is possible the timestamps of the files are being updated which would invalidate the cache.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.