When using Rails inside a Docker container several posts, (including one on docker.com) use the following pattern:
Dockerfile
do ADD Gemfile
and ADD Gemfile.lock
, then RUN bundle install
.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:
Gemfile.lock
should be in your repository, and:
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?
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With