【发布时间】:2016-09-02 21:14:40
【问题描述】:
我在我的 Rails 应用程序中使用 Docker。 现在我尝试在新机器上构建它并遇到一些问题。
当我运行docker-compose -f dcom-dev.yml run --user $(id -u) web bundle install
它开始工作,但失败了
An error occurred while installing debug_inspector (0.0.2), and Bundler cannot continue.
Make sure that `gem install debug_inspector -v '0.0.2'` succeeds before bundling.
如果我尝试docker-compose -f dcom-dev.yml run --user $(id -u) web gem install debug_inspector -v '0.0.2',它会成功执行,告诉该 gem 已安装。
在安装包的过程中也会产生可怕的输出,例如:
Errno::EACCES: Permission denied @ rb_sysopen - /bundler_cache/extensions/x86_64-linux/2.3.0-static/pg-0.18.4/gem_make.out
或
sudo: unknown uid 1000: who are you?
whoami 运行没有任何问题,所以我不知道,为什么它会问我这么奇怪的问题 :)
dcom-dev.yml:
version: '2'
services:
db:
image: postgres
volumes_from:
- db_data
nginx:
build:
context: ./service/nginx
ports:
- "1935:1935"
- "80:80"
depends_on:
- web
volumes_from:
- records
processor:
build:
context: ./service/processor
ports:
- "3322:22"
volumes_from:
- records
web: &app_base
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes_from:
- bundler_cache
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
- processor
env_file: .env
worker:
<<: *app_base
ports: []
command: bundle exec rake jobs:work
db_data:
image: busybox
volumes:
- /var/lib/postgresql/data
records:
image: busybox
volumes:
- /records
bundler_cache:
image: busybox
volumes:
- /bundler_cache
Dockerfile 中关于 ruby 的部分内容:
FROM buildpack-deps:trusty
# Ruby
# skip installing gem documentation
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc
ENV RUBY_MAJOR 2.3
ENV RUBY_VERSION 2.3.1
ENV RUBY_DOWNLOAD_SHA256 b87c738cb2032bf4920fef8e3864dc5cf8eae9d89d8d523ce0236945c5797dcd
ENV RUBYGEMS_VERSION 2.6.6
# some of ruby's build scripts are written in ruby
# we purge this later to make sure our final image uses what we just built
RUN set -ex \
&& buildDeps=' \
bison \
libgdbm-dev \
ruby \
' \
&& apt-get update \
&& apt-get install -y --no-install-recommends $buildDeps \
&& rm -rf /var/lib/apt/lists/* \
&& curl -fSL -o ruby.tar.gz "http://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" \
&& echo "$RUBY_DOWNLOAD_SHA256 *ruby.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/ruby \
&& tar -xzf ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& rm ruby.tar.gz \
&& cd /usr/src/ruby \
&& { echo '#define ENABLE_PATH_CHECK 0'; echo; cat file.c; } > file.c.new && mv file.c.new file.c \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove $buildDeps \
&& gem update --system $RUBYGEMS_VERSION \
&& rm -r /usr/src/ruby
ENV BUNDLER_VERSION 1.12.5
RUN gem install bundler --version "$BUNDLER_VERSION"
# install things globally, for great justice
# and don't create ".bundle" in all our apps
ENV GEM_HOME /usr/local/bundle
ENV BUNDLE_PATH="$GEM_HOME" \
BUNDLE_BIN="$GEM_HOME/bin" \
BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $BUNDLE_BIN:$PATH
RUN mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
&& chmod 777 "$GEM_HOME" "$BUNDLE_BIN"
===============更新1================
这是bundle instal --verbose 的输出
Errno::EACCES: Permission denied @ rb_sysopen - /bundler_cache/extensions/x86_64-linux/2.3.0-static/debug_inspector-0.0.2/gem_make.out
/usr/local/lib/ruby/2.3.0/open-uri.rb:37:in `initialize'
/usr/local/lib/ruby/2.3.0/open-uri.rb:37:in `open'
/usr/local/lib/ruby/2.3.0/open-uri.rb:37:in `open'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:215:in `write_gem_make_out'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:135:in `build_error'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:174:in `rescue in build_extension'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:159:in `build_extension'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:201:in `block in build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:198:in `each'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:198:in `build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/installer.rb:747:in `build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/installer.rb:299:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:143:in `block in install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/rubygems_integration.rb:169:in `preserve_paths'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:135:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/gem_installer.rb:57:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/gem_installer.rb:15:in `install_from_spec'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/parallel_installer.rb:91:in `block in worker_pool'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:65:in `apply_func'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:60:in `block in process_queue'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:57:in `loop'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:57:in `process_queue'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:29:in `block (2 levels) in initialize'
我可以看到它尝试使用 ruby 2.3.0,而我的 Gemfile 使用 2.3.1 指定。通常它会说话,但现在保持沉默。
这一切可能有什么问题?我该怎么办?谢谢!
==========更新2==================
我意识到如果我在没有--user $(id -u) 的情况下运行命令会更好,所以我运行docker-compose -f dcom-dev.yml run web bundle install,它给了我这样的输出:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /bundler_cache/gems/nokogiri-1.6.7.2/ext/nokogiri
/usr/local/bin/ruby -r ./siteconf20160904-1-1ej0stt.rb extconf.rb
Cannot allocate memory - /usr/local/bin/ruby -r ./siteconf20160904-1-1ej0stt.rb extconf.rb 2>&1
Gem files will remain installed in /bundler_cache/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /bundler_cache/extensions/x86_64-linux/2.3.0-static/nokogiri-1.6.7.2/gem_make.out
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:76:in ``'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:76:in `run'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/ext_conf_builder.rb:48:in `block in build'
/usr/local/lib/ruby/2.3.0/tempfile.rb:295:in `open'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/ext_conf_builder.rb:31:in `build'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:164:in `block (2 levels) in build_extension'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:163:in `chdir'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:163:in `block in build_extension'
/usr/local/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:162:in `build_extension'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:201:in `block in build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:198:in `each'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:198:in `build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/installer.rb:747:in `build_extensions'
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/installer.rb:299:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:143:in `block in install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/rubygems_integration.rb:169:in `preserve_paths'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:135:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/gem_installer.rb:57:in `install'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/gem_installer.rb:15:in `install_from_spec'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer/parallel_installer.rb:91:in `block in worker_pool'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:65:in `apply_func'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:60:in `block in process_queue'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:57:in `loop'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:57:in `process_queue'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/worker.rb:29:in `block (2 levels) in initialize'
An error occurred while installing debug_inspector (0.0.2), and Bundler cannot
continue.
Make sure that `gem install debug_inspector -v '0.0.2'` succeeds before
bundling.
显然,gem install debug_inspector -v '0.0.2' 成功了。
我也不知道我是否应该使用--user。如果没有,我将 bundler 作为 sudo 运行,这很糟糕,如果我使用,用户无权写入 bundler 文件夹。
【问题讨论】:
-
你用的是什么图片?
标签: ruby-on-rails docker rubygems bundle docker-compose