簡體   English   中英

如何更新 dockerfile 以使用 rvm 設置 ruby 版本

[英]How to Update dockerfile to set ruby version using rvm

我是 docker 的新手,我正在開發一個項目,我們在 docker 容器中本地運行應用程序。 有一個 dockerfile 正在從 amazonlinux 中提取基本映像。 我在工作流程中使用 docker-compose。 我有步驟使用 rvm 安裝 ruby 2.7.5 但是當我嘗試使用 docker-compose 運行測試時docker-compose run test bundle exec bin/rspec我收到錯誤Your Ruby version is 3.0.3, but your Gemfile specified 2.7.5 你可以看到它正在從 amazon-linux-extras 中獲取 ruby 版本而不是 rvm 我查看了一堆線程但到目前為止沒有運氣。 有什么辦法可以將 ruby 版本設置為 2.7.5?

如果您使用amazon-linux-extras安裝了您想要的 Ruby 版本怎么辦?

所以而不是: RUN amazon-linux-extras enable python3.8 ruby3.0 \

使用: RUN amazon-linux-extras enable python3.8 ruby2.7 \

我認為這應該可以解決問題:

解決方案

而不是使用這一行:

RUN rvm use $RUBY_VERSION

你應該使用這個:

RUN rvm --default use $RUBY_VERSION

說明

因為這個命令只會在當前shell中設置正確的RUBY_VERSION:

RUN rvm use $RUBY_VERSION

所以當你執行這一行時,

docker-compose run --rm --service-ports --use-aliases -e RACK_ENV=test test bundle exec bin/rspec

將創建另一個新的 shell,它將使用默認的 ruby 版本,該版本自動設置為 3.0.3(當您使用RUN amazon-linux-extras enable python3.8 ruby3.0安裝它時)

這就是錯誤的原因:

Your Ruby version is 3.0.3, but your Gemfile specified 2.7.5

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM