2017-10-18 146 views
0

这里新增了ruby和bundler。 我在泊坞窗图像与此泊坞窗文件安装它们:如何使用dockerfile安装ruby和bundler?

FROM alpine:3.5 

# Install Ruby, Ruby Bundler and other ruby dependencies 

RUN apk add --update \ 
     ruby ruby-bigdecimal ruby-bundler \ 
     ca-certificates libressl \ 
     libressl-dev build-base ruby-dev \ 
     ruby-rdoc ruby-io-console ruby-irb; \ 
\ 
    && bundle config build.nokogiri --use-system-libraries; \ 
    && bundle config git.allow_insecure true; \ 
\ 
    && gem install json foreman --no-rdoc --no-ri; \ 
    && gem cleanup; \ 
    && rm -rf /usr/lib/ruby/gems/*/cache/*; \ 
    && apk del libressl-dev build-base ruby-dev; \ 
    && rm -rf /var/cache/apk/* /tmp; 

CMD ["bundle"] 

当我运行做码头工人来看,我得到:

Don't run Bundler as root. Bundler can ask for sudo if it is needed, 
and installing your bundle as root will break this application for all 
non-root users on this machine. 
Could not locate Gemfile or .bundle/ directory 

我该如何解决这个问题?我只是想安装Ruby和Ruby-捆绑,并用此来完成...

+0

是机器有非root用户? –

+0

这是一个码头集装箱,所以我不这么认为。 – Becks

+0

我也没有。为何不忽略警告? –

回答

2

有预建ruby图像(Alpine 3.6 Ruby 2.4),其中包括bundler。开始使用它们比较容易,因为它们通常使用当前的“最佳实践”来构建。

请注意,他们在映像构建中设置BUNDLE_SILENCE_ROOT_WARNING环境变量与ENV指令,以删除root警告。

你通常不会运行bundlerCMD的容器或者,你可能会在一个RUN图像生成步骤运行bundler虽然。

运行容器中,作为非root用户是不是在任何情况下一个坏主意。使用USER指令来改变它。

FROM ruby:2.4-stretch 
WORKDIR /app 
ADD . /app/ 
RUN set -uex; \ 
    bundle install; \ 
    adduser -D rubyapp; \ 
    mkdir -p /app/data; \ 
    chown rubyapp /app/data 
USER rubyapp 
CMD [ "ruby", "whatever.rb" ] 
+0

我决定建立这个容器从Ubuntu的形象开始。其实我现在只处理“无法找到的Gemfile” – Becks

+0

的['2.4 stretch'(https://github.com/docker-library/ruby/blob/9390129c08cc19668fc482edfd7d7c5a890a80eb/2.4/stretch/Dockerfile)图像会非常接近Ubuntu。在运行'bundle'之前,'Gemfile'和你的应用程序应该是'COPY'd或'ADD'ed图像 – Matt