【问题标题】:Docker failed to build on Rails bundle Install rakeDocker 无法在 Rails 捆绑包上构建安装 rake
【发布时间】:2017-11-07 18:55:34
【问题描述】:

我使用Docker for Windows 为 Rails(v5) 应用程序运行图像。

当我执行docker-compose build 时,我收到此错误。我不知道去哪里调试和/或解决这个问题。

这是我的Dockerfile

FROM ruby:2.3.3-slim

RUN apt-get update && apt-get install -y build-essential
RUN apt-get install -y libmysqlclient-dev
RUN apt-get install -y mysql-client
RUN apt-get install -y libmagickwand-dev imagemagick
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs
RUN apt-get install -y git
#RUN npm install -g phantomjs

RUN gem update --system

RUN mkdir -p /MyImage
WORKDIR /MyImage
COPY Gemfile Gemfile
COPY Gemfile.lock Gemfile.lock
RUN gem install bundler
RUN bundle install

COPY package.json package.json
RUN npm update
RUN npm install

COPY . /MyImage

CMD [ "foreman", "start" ]

如果我的错误,这是一个日志:

Step 15/20 : RUN bundle install
 ---> Running in 4bf360b89cb7
The git source `git://github.com/acrogenesis/owlcarousel-rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/sinatra/sinatra.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Fetching source index from https://rubygems.org/
Fetching source index from https://rails-assets.org/
Fetching git://github.com/sinatra/sinatra.git
Fetching git://github.com/acrogenesis/owlcarousel-rails.git
Fetching gem metadata from https://rails-assets.org/..
Fetching rake 12.1.0
Installing rake 12.1.0
Errno::ENOENT: No such file or directory @ rb_sysopen -
/usr/local/lib/ruby/site_ruby/2.3.0/bundler/templates/Executable
An error occurred while installing rake (12.1.0), and Bundler cannot continue.
Make sure that `gem install rake -v '12.1.0'` succeeds before bundling.

In Gemfile:
  autonumeric-rails was resolved to 2.0.0.1, which depends on
    jquery-rails was resolved to 4.3.1, which depends on
      railties was resolved to 5.0.6, which depends on
        rake
ERROR: Service 'MyImage' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 5

但是当我直接在容器的外壳中执行gem install rake -v '12.1.0' 时,一切都安装得很好。

【问题讨论】:

    标签: ruby-on-rails ruby docker docker-compose dockerfile


    【解决方案1】:

    请尝试按照错误消息中的说明自行安装 rake:

    gem install rake -v '12.1.0'
    

    调试:

    1. 注释掉Dockerfile 中从RUN bundle install 开始到结束的所有行;

    2. 然后运行docker build -t test:0.0 .;

    3. 开始互动会话:docker run -it test:0.0 /bin/bash;

    4. 尝试手动执行gem install rake -v '12.1.0'...

    【讨论】:

    • @JudgeProphet 你能先运行gem install rake -v '12.1.0',然后在同一个会话中再次运行bundle install吗?还会出现错误吗?
    • 顺便说一句。您的映像中安装了哪个版本的bundler gem? gem update --system 命令仅更新系统 gem。所以bundler 可能仍然过时。
    • 我的意思是如果gem install 运行良好,问题可能与bundler 本身有关。
    • 我更新了 DockerFile 以强制安装 Bundler,但仍然出现同样的错误
    • @JudgeProphet 听起来很疯狂,但是您可以尝试手动添加或运行:RUN mkdir -p /usr/local/lib/ruby/site_ruby/2.3.0/bundler/templates/Executable? =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-24
    相关资源
    最近更新 更多