Docker:找不到RVM命令

时间:2015-01-24 19:35:59

标签: rvm vagrant docker

我正在使用Vagrant安装docker来启动虚拟机 还安装了RVM和Ruby 2.1:

# -*- mode: ruby -*-
# vi: set ft=ruby :

$rvm= <<SCRIPT
unset GEM_HOME
curl -L https://rvm.io/mpapis.asc | gpg --import -
curl -L https://get.rvm.io | bash -s stable
echo "source /home/vagrant/.rvm/scripts/rvm" >> .bash_history
echo 'gem: --no-ri --no-rdoc' > ~/.gemrc
rvm install 2.1.1
SCRIPT

$setup= <<SCRIPT
docker build -t campaign/development:latest /home/vagrant
#docker run -d -p 3000:3000 -v /home/vagrant:/home/vagrant --name development development:latest
SCRIPT

Vagrant.configure(2) do |config|
  config.vm.box = "hashicorp/precise64"      
  config.vm.provider "virtualbox" do |vb|
    vb.memory = 2048
  end      
  # need a private network for NFS shares to work
  config.vm.network "private_network", ip: "192.168.50.4"      
  # Rails Server Port Forwarding
  config.vm.network "forwarded_port", guest: 3000, host: 3000
  config.vm.synced_folder ".", "/home/vagrant", create: true, type: "nfs"      

  # Install RVM
  config.vm.provision "shell", inline: $rvm

  # Install latest docker
  config.vm.provision "docker"
  config.vm.provision "shell", run: "always", inline: $setup
end

build命令命中以下Dockerfile:

FROM rails

RUN adduser web --home /home/vagrant --shell /bin/bash --disabled-password --gecos ""
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Separate Gemfile ADD so that `bundle install` can be cached more effectively
RUN chown -R web:web /home/vagrant &&\
    mkdir -p /home/vagrant/bundle &&\
    chown -R web:web /home/vagrant/bundle
ADD Gemfile      /home/vagrant/
ADD Gemfile.lock /home/vagrant/   

RUN rvm use 2.1.1@campaign --create &&\
    bundle install --development

...

当我进入STEP 6时,RUN rvm命令返回:

Step 6 : RUN rvm use 2.1.1@campaign --create && bundle install --development
---> Running in 86e80ff96036
/bin/sh: rvm: command not found
INFO[0012] The command [/bin/sh -c rvm use 2.1.1@campaign 
--create &&    bundle install --development] returned a non-zero code: 127

我很困惑,因为我可以在框中运行并运行RVM命令, 我的ruby / gemset已创建。我是否应该尝试运行RVM命令 在Dockerfile中还是应该只有一个在Vagrantfile中运行的安装脚本?

2 个答案:

答案 0 :(得分:3)

使用安装的脚本启动rvm。该脚本必须添加到您的会话中,但不会直接在您Dockerfile中使用该脚本添加。您可以尝试使用:

  

RUN / bin / bash -l -c“rvm使用2.1.1@campaign - 创建捆绑安装   --development“

答案 1 :(得分:1)

如果找不到rvm,但需要在容器内使用,可以通过键入以下命令将其添加到路径:

bash -l -c PATH=$PATH:/path/to/your/rvm/binary

或者将其添加到默认容器用户的.profile或.bashrc(在/ root或/ home / username下)