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?
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.