Instantly share code, notes, and snippets.

@deepak /Dockerfile
Last active May 27, 2018

What would you like to do?
Dockerfile for installing ruby using rbenv
# am facing issue
FROM ubuntu:12.04
MAINTAINER Deepak Kannan ""
RUN apt-get -y install python-software-properties
RUN apt-get -y update
# install essentials
RUN apt-get -y install build-essential
RUN apt-get install -y -q git
RUN add-apt-repository -y ppa:chris-lea/nginx-devel
RUN apt-get install -y -q nginx-full
# Install rbenv
RUN git clone /usr/local/rbenv
RUN echo '# rbenv setup' > /etc/profile.d/
RUN echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/
RUN echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/
RUN echo 'eval "$(rbenv init -)"' >> /etc/profile.d/
RUN chmod +x /etc/profile.d/
# install ruby-build
RUN mkdir /usr/local/rbenv/plugins
RUN git clone /usr/local/rbenv/plugins/ruby-build
ENV RBENV_ROOT /usr/local/rbenv
ENV PATH "$RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# does not work. PATH is set to
# $RBENV_ROOT/shims:$RBENV_ROOT/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# install ruby2
RUN rbenv install 2.0.0-p247

This comment has been minimized.


deepak commented Jul 4, 2013

PATH is not set properly
can set PATH as
ENV PATH /usr/local/rbenv/shims:/usr/local/rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
but that is not elegant


This comment has been minimized.

johnbellone commented Aug 14, 2013

@deepak Instead of jamming the environment on the fly don't you think you could do:

RUN bash -c 'rbenv install 2.0.0-p247'

This comment has been minimized.

parkerault commented Sep 29, 2013

I've always been a bit confused about the environment that Dockerfile commands are run in (I really should spend a few hours figuring this out), but my workaround has always been to source whatever scripts set your environment variables in your login shell at the start of any command that requires shell magic; RUN . ~/.bashrc && rbenv install 2.0.0-p247 for example. I was never able to get RUN /bin/bash -c 'rbenv install 2.0.0-p247' to work, but like I said, I'm a bit unsure about what is happening behind the scenes.


This comment has been minimized.

johnbellone commented Oct 19, 2013

@parkerault I have a docker image for this, but its basically bash -l -c 'rbenv' which starts a login shell and sources the profile. Or you could just fork my docker image: johnbellone/rbenv


This comment has been minimized.

jcarley commented Sep 2, 2014

Don't put the quotes around the path string. Leaving them off set the path correctly for me and evaluated the $RBENV_ROOT variable. Then the RUN rbenv install 2.0.0-p247 works just fine. I'm running docker 1.2, with a Ubuntu 14.04 image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment