raf*_*afi 4 rspec ruby-on-rails bundler docker docker-compose
我正在为我的 rails 应用程序使用 docker-compose。
我最近更新了我的 master 分支,将 rails 版本更新为 5.2.3 —— 我通过 docker-compose 运行了 bundle install:
docker-compose run web bundle install
看起来它运行良好,但是当我尝试运行 rspec 时出现此错误:
Could not find activesupport-5.2.3 in any of the sources
Run `bundle install` to install missing gems.
Run Code Online (Sandbox Code Playgroud)
我尝试运行bundle update activesupport- 并得到这个:
Bundler attempted to update activesupport but its version stayed the same
Bundle updated!
Run Code Online (Sandbox Code Playgroud)
所以我尝试手动安装 gem:
docker-compose run web gem install activesupport
Fetching activesupport-5.2.3.gem
Successfully installed activesupport-5.2.3
1 gem installed
Run Code Online (Sandbox Code Playgroud)
然后我尝试再次运行 rspec,同样的事情:
$ docker-compose run web bin/rspec ./spec/some_spec.rb
Could not find activesupport-5.2.3 in any of the sources
Run `bundle install` to install missing gems.
Run Code Online (Sandbox Code Playgroud)
docker-compose 是否没有注意到 gem/bundler 的变化?我在这里错过了什么吗?
每个docker-compose run都启动一个新容器。运行两次,再运行docker ps -a你会看到两个Exited容器。
您需要bundle install在Dockerfile.
作为旁注提示,通常的做法是首先仅复制Gemfile和Gemfile.lock文件,运行bundle install,然后才复制整个应用程序。通过这种方式,您可以创建两个单独的层,并避免在应用程序文件更改时重新安装所有 gem。
这里有一个Dockerfile供参考。
FROM ruby:2.5.3
WORKDIR $RAILS_ROOT
# ... more custom stuff here ...
# Pre-install gems
COPY Gemfile* ./
RUN gem install bundler && bundle install --jobs=3 --retry=3
# Copy app files
COPY . .
RUN chmod -R 755 $RAILS_ROOT/bin
# Run server
EXPOSE 3000
CMD bundle exec rails s -b 0.0.0.0 -p 3000
Run Code Online (Sandbox Code Playgroud)
docker-compose run 每次调用时都会创建一个新容器,您的更改不会持续存在。
如果您希望您的更改保持不变,请使用docker-compose exec,它会在正在运行的容器中运行您的命令。
| 归档时间: |
|
| 查看次数: |
3037 次 |
| 最近记录: |