Enabling rvm in a Dockerfle – The perils of bash vs. sh

The Ruby installer says to run ‘source /usr/local/rvm/scripts/rvm’ as a way to enable the environment for rvm but with Docker this gives an error indicating that ‘source’ is a bash builtin. Using the sh equivalent to run a script, you also get an error,

Step 4 : RUN . /usr/local/rvm/bin/rvm
 ---> Running in 534f12b27222
/bin/sh: 7: /usr/local/rvm/bin/rvm: Syntax error: "(" unexpected (expecting "fi")

This is because the RUN operation uses /bin/sh to execute tasks

RUN /bin/bash -c "source /usr/local/rvm/scripts/rvm \
 && gem update --system --no-rdoc --no-ri \
 && gem update --no-rdoc --no-ri \
 && gem install --no-rdoc --no-ri bundler \
 && gem install --no-rdoc --no-ri libv8 \
 && gem install --no-rdoc --no-ri mysql2"

The whole operation has to be run inside the quotes, you can’t the source as one RUN and the gem commands as individual RUNs, you’ll get a ‘gem: command not found’ error.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s