Search code examples
ruby-on-railsdockerbundler

How do I update Gemfile.lock on my Docker host?


When using Rails inside a Docker container several posts, (including one on docker.com) use the following pattern:

  1. In Dockerfile do ADD Gemfile and ADD Gemfile.lock, then RUN bundle install.
  2. Create a new Rails app with docker-compose run web rails new.

Since we RUN bundle install to build the image, it seems appropriate to docker-compose build web after updating the Gemfile.

This works insomuch as the gemset will be updated inside the image, but:

The Gemfile.lock on the Docker host will not be updated to reflect the changes to the Gemfile. This is a problem because:

  1. Gemfile.lock should be in your repository, and:

  2. It should be consistent with your current Gemfile.


So:

How can one update the Gemfile.lock on the host, so it may be checked in to version control?


Solution

  • Executing the bundle inside run does update the Gemfile.lock on the host:

    docker-compose run web bundle
    

    However: You must still also build the image again.