如何使用RVM更新Dockerfile以设置Ruby版本
我是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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您安装了想要使用
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 \
我认为这应该解决问题:
解决方案
而不是使用这一行:
您应该使用以下内容:
解释
因为此命令只会在当前 shell 中设置正确的 RUBY_VERSION:
因此,当您执行此行时,
将创建另一个新 shell,并且它将使用默认的 ruby 版本,该版本会自动设置为 3.0.3(当您使用 RUN amazon-linux-extras enable python3.8 ruby3.0 安装它时),
这就是为什么错误是:
希望这有帮助
I think this should solve the problem:
Solution
Instead of using this line:
You should use this:
Explaination
Because this command will only set the correct RUBY_VERSION in the current shell:
So when you execute this line,
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:
Hope this helps