如何使用RVM更新Dockerfile以设置Ruby版本

发布于 2025-01-18 02:30:55 字数 241 浏览 2 评论 0原文

我是Docker的新手,我正在从事一个项目,我们正在Docker容器中本地运行应用程序。有一个Dockerfile正在从Amazonlinux中提取基本图像。我正在使用Docker-Compose进行工作流程。我有使用RVM安装Ruby 2.7.5的一步.3,但您的Gemfile指定了2.7.5 。您可以看到它正在从Amazon-Linux-Extras而不是RVM拾取Ruby版本 我看着一堆线,但到目前为止没有运气。有什么办法可以将Ruby版本设置为2.7.5?

I am new to docker and I am working on a project where we are running application locally in docker container. There is a dockerfile that is pulling base image from amazonlinux. I am using docker-compose for the workflow. I have step to install ruby 2.7.5 using rvm but when I try to run tests using docker-compose docker-compose run test bundle exec bin/rspec I get error Your Ruby version is 3.0.3, but your Gemfile specified 2.7.5. You can see it is picking up the ruby version from amazon-linux-extras and not rvm
I looked at bunch of threads but no luck so far. Is there any way I can set the ruby version to 2.7.5 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幽蝶幻影 2025-01-25 02:30:55

如果您安装了想要使用Amazon-Linux-Extras的Ruby版本,该怎么办?

因此,而不是:
运行Amazon-Linux-Extras启用Python3.8 Ruby3.0 \

使用:
运行Amazon-Linux-Extras启用Python3.8 Ruby2.7 \

What if you installed the version of Ruby that you want using amazon-linux-extras?

So instead of:
RUN amazon-linux-extras enable python3.8 ruby3.0 \

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

莫相离 2025-01-25 02:30:55

我认为这应该解决问题:

解决方案

而不是使用这一行:

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 ruby​​3.0 安装它时),

这就是为什么错误是:

Your Ruby version is 3.0.3, but your Gemfile specified 2.7.5

希望这有帮助

I think this should solve the problem:

Solution

Instead of using this line:

RUN rvm use $RUBY_VERSION

You should use this:

RUN rvm --default use $RUBY_VERSION

Explaination

Because this command will only set the correct RUBY_VERSION in the current shell:

RUN rvm use $RUBY_VERSION

So when you execute this line,

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

Another new shell will be create, and it's gonna use the default ruby version which automatically be set as 3.0.3 (when you install it with RUN amazon-linux-extras enable python3.8 ruby3.0)

That's the reason why the error is:

Your Ruby version is 3.0.3, but your Gemfile specified 2.7.5

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文