Long story short:
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'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?
If you won't, always have the ruby
from rvm
add -l
option.
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"]
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:/#
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…