我在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'
它成功执行,告诉宝石被安置。
同样在安装捆绑包时会产生可怕的输出,如:
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
关于ruby的Dockerfile
的一部分:
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指定。通常它会说它,但现在保持沉默。
这一切有什么问题?我该怎么办?谢谢!
========== Upd 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
。如果没有,我将捆绑包作为sudo运行,如果我使用,那么用户没有权限写入bundler文件夹。
答案 0 :(得分:1)
知道了!
由于我在DigitalOcean上使用Droplet,我设法发现错误Cannot allocate memory
意味着我需要创建一个交换。这确实有帮助。
问题是here
答案 1 :(得分:0)
您的新计算机上的用户ID不同,您似乎已将此用户ID硬编码到图像中,至少以文件权限的形式。标记--user $(id -u)
告诉docker-compose
以您的主机上的用户身份运行您的容器,在新计算机上运行1000,并且该uid无法访问您在图像中创建的文件。
要获得更完整的答案,我们需要了解您的dcom-dev.yml的内容以及您用于构建图像的任何Dockerfile。