如何在Docker中正确安装RVM? [英] How to correctly install RVM in Docker?

查看:137
本文介绍了如何在Docker中正确安装RVM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我的Dockerfile中的内容:

RUN gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
RUN curl -L https://get.rvm.io | bash -s stable
RUN /bin/bash -l -c "rvm requirements"
RUN /bin/bash -l -c "rvm install 2.3.3"

工作正常,但是,当我启动容器时,看到的是:

Works just fine, however, when I start the container, I see this:

$ docker -it --rm myimage /bin/bash
/root# ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
/root# /bin/bash -l -c "ruby --version"
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]

显然,这不是我想要的.据我了解,问题在于bash在默认情况下不会运行/etc/profile.这就是为什么Ruby不是来自RVM安装的原因.我该如何解决?

Obviously, this is not what I want. As far as I understand, the problem is that bash doesn't run /etc/profile by default. That's why Ruby is not coming from the RVM installation. How can I fix that?

推荐答案

长话短说:

docker -it --rm myimage /bin/bash命令不会将bash作为登录shell启动.

docker -it --rm myimage /bin/bash command does not start bash as a login shell.

说明:

当您运行$ docker -it --rm myimage /bin/bash时,它会调用bash而没有-l选项,这会使bash像被作为登录shell一样被调用,rvm的初始化取决于source -ing /path/to/.rvm/scripts/rvm/etc/profile.d/rvm.sh,并且该初始化是在.bash_profile.bashrc或任何其他初始化脚本中进行的.

When you run $ docker -it --rm myimage /bin/bash it's invoke bash without the -l option which make bash act as if it had been invoked as a login shell, rvm initializations depends on the source-ing /path/to/.rvm/scripts/rvm or /etc/profile.d/rvm.sh and that initialization is in .bash_profile or .bashrc or any other initialization scripts.

我该如何解决?

How can I fix that?

如果不这样做,请始终从rvm中添加ruby并添加-l选项.

If you won't, always have the ruby from rvm add -l option.

这是一个由rvm安装ruby的Dockerfile:

Here is a Dockerfile with installed ruby by rvm:

FROM Debian

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update -q && \
    apt-get install -qy procps curl ca-certificates gnupg2 build-essential --no-install-recommends && apt-get clean

RUN gpg2 --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3
RUN curl -sSL https://get.rvm.io | bash -s
RUN /bin/bash -l -c ". /etc/profile.d/rvm.sh && rvm install 2.3.3"
# The entry point here is an initialization process, 
# it will be used as arguments for e.g.
# `docker run` command 
ENTRYPOINT ["/bin/bash", "-l", "-c"]

运行容器:

➠ docker_templates : docker run -ti --rm rvm 'ruby -v'
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
➠ docker_templates : docker run -ti --rm rvm 'rvm -v'
rvm 1.29.1 (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]
➠ docker_templates : docker run -ti --rm rvm bash
root@efa1bf7cec62:/# rvm -v
rvm 1.29.1 (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io/]
root@efa1bf7cec62:/# ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-linux]
root@efa1bf7cec62:/# 

这篇关于如何在Docker中正确安装RVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆