2014-09-13 54 views
2

我必須通過創建以下文件泊塢窗如何檢查泊塢窗容器內的紅寶石版本

# Select ubuntu as the base image 
FROM ubuntu 

# Install nginx, nodejs and curl 
RUN apt-get update -q 
RUN apt-get install -qy nginx 
RUN apt-get install -qy curl 
RUN apt-get install -qy nodejs 
RUN echo "daemon off;" >> /etc/nginx/nginx.conf 

# Install rvm, ruby, bundler 
RUN curl -sSL https://get.rvm.io | bash -s stable 
RUN /bin/bash -l -c "rvm requirements" 
RUN /bin/bash -l -c "rvm install 2.1.0" 
RUN /bin/bash -l -c "gem install bundler --no-ri --no-rdoc" 

# Add configuration files in repository to filesystem 
ADD config/container/nginx-sites.conf /etc/nginx/sites-enabled/default 
ADD config/container/start-server.sh /usr/bin/start-server 
RUN chmod +x /usr/bin/start-server 

# Add rails project to project directory 
ADD ./ /rails 

# set WORKDIR 
WORKDIR /rails 

# bundle install 
RUN /bin/bash -l -c "bundle install" 

# Publish port 80 
EXPOSE 80 

# Startup commands 
ENTRYPOINT /usr/bin/start-server 

打造泊塢窗容器,當我去的容器內,併發出命令紅寶石-v它拋出慶典:紅寶石:命令不發現

可以在任何一個可以幫助我在做這個

回答

0

安裝RVM後,您沒有設置默認紅寶石。試着在安裝後設置默認的ruby。

RUN /bin/bash -l -c "rvm install 2.1.0" 
RUN /bin/bash -l -c "rvm use 2.1.0 --default" 
+0

那麼,爲什麼我們不能用''ruby''作爲一個典型的倉? (爲什麼我們總是需要bash -c -l) – 2017-01-25 08:04:04

4

最近我花了一些時間搞亂了RVM,Ruby和Docker。這個答案可能不是你要找的東西,但無論如何需要說:如果你不是絕對需要RVM,那麼不要在你的docker文件中使用它。你已經注意到了一個缺點:必須用/ bin/bash -lc預佔你的命令。如果你想讓一個非root用戶在你的Docker容器中運行一個ruby程序,你會遇到另一個不利因素。此外,當您運行bash shell時,您的問題很可能與Docker不加載.bashrc或.bash_profile(我忘記了哪一個RVM修改)有關。

而是使用從源代碼編譯的Ruby:

RUN apt-get update 
RUN apt-get install -yq build-essential openssl libreadline6 libreadline6-dev curl git-core \ 
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev \ 
autoconf libc6-dev ncurses-dev automake libtool bison subversion libmysqlclient-dev 

ADD http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz /tmp/ 
RUN cd /tmp && tar -xzf /tmp/ruby-2.1.2.tar.gz 
RUN cd /tmp/ruby-2.1.2/ && ./configure --disable-install-doc && make && make install 
RUN rm -rf /tmp/* 

ADD http://production.cf.rubygems.org/rubygems/rubygems-2.4.1.tgz /tmp/ 
RUN cd /tmp && tar -xzf /tmp/rubygems-2.4.1.tgz 
RUN cd /tmp/rubygems-2.4.1 && ruby setup.rb 
RUN rm -rf /tmp/* 

RUN echo "gem: --no-ri --no-rdoc" > ~/.gemrc 
RUN gem install bundler --no-rdoc --no-ri 
+0

這絕對是IMHO的方式。你可以用獨立的圖像完成你所有耗費時間的紅寶石建築,並且在此後安心。謝謝你的提示! – Ben 2015-05-07 22:14:43