I struggled with this for about an hour today, so I thought I'd throw up a blog post for anyone else stumbling through the bundler 2.0.1 gem upgrade with their Dockerfile.

Most people have something that looks like this somewhere towards the end of their Dockerfile:

COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

If you upgrade your Gemfile.lock to use bundler 2.0.1, you'll likely see an error like this:

Step 14/16 : COPY Gemfile Gemfile.lock ./
 ---> Running in 512b1d840286
Step 15/16 : RUN /usr/local/bin/bundle update --bundler
 ---> Running in c0333921c391
You must use Bundler 2 or greater with this lockfile.
The command '/bin/sh -c /usr/local/bin/bundle update --bundler' returned a non-zero code: 20

But never fear! You likely need to either unset or export the BUNDLER_VERSION environment variable, like I did:

COPY Gemfile Gemfile.lock ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

That did the trick for me, and I was back up and running with a bundler 2.0.1 setup. If you're still running into issues, following the steps in The Bundler 2 Upgrade Guide was what led to my solution.