Docker:找不到RVM命令

我使用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 

生成命令命中下面的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 

我只是困惑,因为我可以ssh到盒子上运行RVM命令,我的ruby / gemset被创build。 我甚至应该试图在Dockerfile中运行RVM命令,还是应该在Vagrantfile中运行一个安装脚本?

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

RUN / bin / bash -l -c“rvm use 2.1.1@campaign –create bundle install –development”

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

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

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