1

I want to install rbenv on Docker which seems to work but I can't reload the shell.

FROM node:0.10.32-slim

RUN \
      apt-get update \
  &&  apt-get install -y sudo

RUN \
      echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
  &&  groupadd r \
  &&  useradd r -m -g r -g sudo

USER r

RUN \
      git clone https://github.com/sstephenson/rbenv.git ~/.rbenv \
  &&  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
  &&  echo 'eval "$(rbenv init -)"' >> ~/.bashrc

RUN rbenv # check if it works...

When I run this I get:

docker build .       

..

Step 5 : RUN rbenv
/bin/sh: 1: rbenv: not found

From what I understand, I need to reload the current shell so I can install ruby versions. Not sure if I am on the right track.

Also see: Using rbenv with Docker

Community
  • 1
  • 1
Rimian
  • 36,864
  • 16
  • 117
  • 117

2 Answers2

5

The RUN command executes everything under /bin/sh, thus your bashrc is not evaled at any point.

use this

&& export PATH="$HOME/.rbenv/bin:$PATH" \

which would append rbenv to /bin/sh's PATH.

Full Dockerfile

FROM node:0.10.32-slim

RUN \
      apt-get update \
  &&  apt-get install -y sudo

RUN \
      echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers \
  &&  groupadd r \
  &&  useradd r -m -g r -g sudo

USER r

RUN \
      git clone https://github.com/sstephenson/rbenv.git ~/.rbenv \
  &&  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc \
  &&  echo 'eval "$(rbenv init -)"' >> ~/.bashrc \
  &&  export PATH="$HOME/.rbenv/bin:$PATH"

RUN rbenv # check if it works...
Andizzle
  • 51
  • 1
  • 3
3

I'm not sure how Docker works, but it seems like maybe you're missing a step where you source ~/.bashrc, which is preventing you from having the rbenv executable in your PATH. Try adding that right before your first attempt to run rbenv and see if it helps.

You can always solve PATH issues by using the absolute path, too. Instead of just rbenv, try running $HOME/.rbenv/bin/rbenv.

If that works, it indicates that rbenv has installed successfully, and that your PATH is not correctly set to include its bin directory.

It looks from reading the other question you posted that docker allows you to set your PATH via an ENV PATH command, like this, for example:

ENV PATH $HOME/.rbenv/bin:/usr/bin:/bin

but you should make sure that you include all of the various paths you will need.

user513951
  • 12,445
  • 7
  • 65
  • 82
  • I tried that actually but I get: /bin/sh: 1: source: not found. Weird. Maybe I shouldn't be using the slim version of the library. – Rimian Nov 12 '14 at 05:18
  • 1
    @Rimian, I updated my answer with another suggestion. It's not a durable solution, but it will probably help you get over this speed bump at least. – user513951 Nov 12 '14 at 05:20
  • Yeah that gets me moving forward, I think. Many thanks! – Rimian Nov 12 '14 at 05:24
  • @Rimian No problem. I updated again with a solution that may actually be the real solution. – user513951 Nov 12 '14 at 05:25