Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 839
davetapley Avatar asked Jun 20 '16 16:06

davetapley


People also ask

How do I update my Gemfile lock?

To automatically update the Gemfile. lock with your current version of Bundler, run bundle update --bundler . In general, it's a good idea to use the latest version of Bundler. That's why my Ruby on Mac script is meant to be run often to keep your system up to date with the latest versions of Bundler and Rubygems.

What is the difference between Gemfile and Gemfile lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions. The Gemfile. lock file is where Bundler records the exact versions that were installed. This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.


1 Answers

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.

like image 173
davetapley Avatar answered Oct 04 '22 15:10

davetapley