How to install RVM in Docker?

This is what I have in my 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 well, 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] 

Obviously, this is not what I want. As far as I understand, the problem is that bash does not start /etc/profile by default. This is why Ruby does not come from installing RVM. How can i fix this?

+5
source share
1 answer

Shortly speaking:

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

Explanation:

When you run $ docker -it --rm myimage /bin/bash it calls bash without the -l option, which makes bash act as if it were called as an input shell, rvm initialization depends on 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 this?

If you want to always have the ruby from rvm add -l option.

Here is the Docker file with ruby installed on rvm :

 FROM debian ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -q && \ apt-get install -qy 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 eg # `docker run` command ENTRYPOINT ["/bin/bash", "-l", "-c"] 

Run the container:

 ➠ 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 :/# 
+8
source

Source: https://habr.com/ru/post/1267139/


All Articles