postmodern / chruby

Changes the current Ruby
MIT License
2.85k stars 190 forks source link

chruby inside Docker - different shell approach needed? #409

Closed rarkins closed 5 years ago

rarkins commented 5 years ago

I'm attempting to build a Dockerfile with multiple versions of Ruby to allow dynamic switching, but I think I'm hitting a shell interactivity problem.

Dockerfile:

FROM renovate/base

USER root

RUN apt-get update && apt-get install -y build-essential

RUN cd /tmp && \
  curl -L https://github.com/postmodern/ruby-install/archive/v0.7.0.tar.gz > ruby-install-0.7.0.tar.gz && \
  tar -xzvf ruby-install-0.7.0.tar.gz && \
  cd ruby-install-0.7.0/ && \
  make install

RUN ruby-install ruby

RUN chmod -R a+rw /usr

USER ubuntu

RUN cd /tmp && curl -L https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz > chruby-0.3.9.tar.gz && \
  tar -xzvf chruby-0.3.9.tar.gz && \
  cd chruby-0.3.9/ && \
  make install

RUN echo "source /usr/local/share/chruby/chruby.sh" >> ~/.bashrc

Logs:

~/github/docker-bundler master*
❯ docker run --rm -it renovate/bundler chruby
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"chruby\": executable file not found in $PATH": unknown.

~/github/docker-bundler master*
❯ docker run --rm -it renovate/bundler bash -l -c chruby
bash: chruby: command not found

~/github/docker-bundler master*
❯ docker run --rm -it renovate/bundler bash
ubuntu@fbbaebe9ed05:/$ chruby
   ruby-2.6.0
ubuntu@fbbaebe9ed05:/$

As you can see, chruby runs once I explicitly run a bash session, but it doesn't run when called directly or even indirectly via bash. I guess it's something to do with aliases and shell interactivity?

Any help would be appreciated.

jbonhag commented 5 years ago

Hi @rarkins! In this case, you'd want an interactive shell as opposed to a login shell. This should do the trick:

docker run --rm -it renovate/bundler bash -i -c chruby
rarkins commented 5 years ago

Thanks!