Bundler::GemNotFound: Could not find rake-12.3.2 in any of the sources
When you add a docker run -v $(pwd):/application
option, it hides everything in the /application
directory in the image and replaces it with the content from your host system. That in particular includes the /application/vendor
directory: any bundle
commands in your Dockerfile are completely ignored, and your host system's ./vendor
directory gets used instead.
There's not really a good answer to this, if you must have live editing and reloading in your deployed container. The Node ecosystem is similar (third-party libraries are in ./node_modules
) and most similar questions are about Node rather than Ruby. Add a volume to Docker, but exclude a sub-folder suggests adding an anonymous volume for ./vendor
; the first time only that you run your application it will get populated from the image, but if you later change your Gemfile it won't get updated and replicating this setup is unnecessarily complicated in cluster environments like Kubernetes.
If you want to try the anonymous-volume path, that could look like
docker run --name rails-chat-tutorial-web ... \ -v $PWD:/application -v /application/vendor \ rails-chat-tutorial$EDITOR Gemfilebundle installdocker stop rails-chat-tutorial-webdocker rm -v rails-chat-tutorial-webdocker run ...
(docker rm -v
will delete the anonymous volume, and it will get recreated on the next docker run
with updated contents. You've told Docker that directory contains important non-code data that must be preserved across runs.)
The sequence that's worked well for me is to develop my application in total ignorance of Docker: develop it locally, run it, write good rspec tests, and generally believe it works. Only then do I docker build
and docker run
an image, without bind-mounting my source code into it. If it breaks then I reproduce the issue on my local development environment, write a test for it, and fix it, then repeat the docker build; docker run
sequence.