我正在使用Vagrant安装了docker的VM
它还安装了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中运行安装脚本?
最佳答案
rvm是使用安装的脚本启动的。该脚本必须添加到您的 session 中,但不能通过在Dockerfile
中直接运行来添加。您可以尝试使用:
> RUN /bin/bash -l -c "rvm use 2.1.1@campaign --create bundle install --development"
关于rvm - Docker : RVM command not found,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28129438/