【发布时间】:2022-01-19 17:03:37
【问题描述】:
我希望使用 Docker 映像 (ruby:3.0) 构建映像,而无需(最终)在本地安装 Ruby。
出于测试目的,我在 Windows 10 WSL2 环境中安装了 Ruby 2.7.0:
$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
我有一个Gemfile:
来源“https://rubygems.org”
gem 'sinatra'
group :development, :test do
gem 'thin'
gem 'sqlite3'
end
并且捆绑器设置为在项目目录中安装 Gems:
$ cat .bundle/config
---
BUNDLE_PATH: "vendor/bundle"
如果我在本地运行bundle install:
$ bundle install
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
Using bundler 2.2.17
Fetching rack 2.2.3
Fetching tilt 2.0.10
Fetching daemons 1.4.1
Fetching sqlite3 1.4.2
Fetching eventmachine 1.2.7
Fetching ruby2_keywords 0.0.5
Installing rack 2.2.3
Installing tilt 2.0.10
Installing sqlite3 1.4.2 with native extensions
Installing ruby2_keywords 0.0.5
Installing daemons 1.4.1
Installing eventmachine 1.2.7 with native extensions
Fetching mustermann 1.1.1
Installing mustermann 1.1.1
Fetching rack-protection 2.1.0
Installing rack-protection 2.1.0
Fetching sinatra 2.1.0
Installing sinatra 2.1.0
Fetching thin 1.8.1
Installing thin 1.8.1 with native extensions
Bundle complete! 3 Gemfile dependencies, 11 gems now installed.
Bundled gems are installed into `./vendor/bundle`
Gem 安装到 ./vendor/bundle 目录:
确认:
$ bundle info thin
* thin (1.8.1)
Summary: A thin and fast web server
Homepage: https://github.com/macournoyer/thin
Source Code: https://github.com/macournoyer/thin
Changelog: https://github.com/macournoyer/thin/blob/master/CHANGELOG
Path: /home/craig/ruby/dev/vendor/bundle/ruby/2.7.0/gems/thin-1.8.1
接下来,我使用ruby:3.0 图像将 Gems 捆绑到项目目录中。
我删除了Gemfile.lock 和./vendor/bundle 目录,然后使用图像运行bundle install:
$ docker run --rm -v "$(pwd)":/src -w /src ruby:3.0 bundle install
Fetching gem metadata from https://rubygems.org/...
Resolving dependencies...
Using bundler 2.2.32
Fetching sqlite3 1.4.2
Fetching eventmachine 1.2.7
Fetching rack 2.2.3
Fetching tilt 2.0.10
Fetching ruby2_keywords 0.0.5
Fetching daemons 1.4.1
Installing ruby2_keywords 0.0.5
Installing tilt 2.0.10
Installing daemons 1.4.1
Installing sqlite3 1.4.2 with native extensions
Installing rack 2.2.3
Fetching mustermann 1.1.1
Installing eventmachine 1.2.7 with native extensions
Installing mustermann 1.1.1
Fetching rack-protection 2.1.0
Installing rack-protection 2.1.0
Fetching sinatra 2.1.0
Installing sinatra 2.1.0
Fetching thin 1.8.1
Installing thin 1.8.1 with native extensions
Bundle complete! 3 Gemfile dependencies, 11 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
这个过程似乎安装了 Gems,但没有安装到 ./vendor/bundle。尝试识别位置会产生错误:
$ bundle info thin
Could not find daemons-1.4.1 in any of the sources
.bundle/config 似乎被忽略了。我猜 Gems 实际上是安装到为运行 bundle install 而创建的容器中。
有没有办法让它使用.bundle/config?
【问题讨论】:
标签: ruby docker rubygems bundler