我必须维护适用于Ruby 1.9.3的旧的Ruby on Rails 2.3.17应用程序,并希望将开发转移到Docker for OS X(Docker版本17.12.0-ce,构建c97c6d6),但主要是目标 - 在主机上拥有文件夹,以避免每次启动新容器时重新安装gem。我尝试使用使用主机目录的Docker卷并在那里安装所有gem。使用以下Dockerfile
FROM zedtux/ruby-1.9.3
RUN apt-get update -qq \
&& apt-get install -y \
build-essential \
libmysqlclient-dev \
libxml2-dev \
libxslt-dev \
libsasl2-2 \
libsasl2-dev \
nodejs \
git \
&& apt-get clean autoclean \
&& apt-get autoremove -y \
&& rm -rf \
/var/lib/apt \
/var/lib/dpkg \
/var/lib/cache \
/var/lib/log
VOLUME /app
VOLUME /bundler-cache
RUN echo "---\ngem: --no-ri --no-rdoc" >> ~/.gemrc
WORKDIR /app
和docker-compose.yml
version: "3.5"
services:
web:
build: .
ports:
- "3000:3000"
volumes:
- /Users/bosko/central_bundle_storage/app-gems:/bundler-cache
- ${PWD}:/app
environment:
GEM_HOME: /bundler-cache
GEM_PATH: /bundler-cache
BUNDLE_PATH: /bundler-cache
PATH: /bundler-cache/bin:$PATH
用以下构建和启动容器后
docker-compose run --rm web bash
我正在安装bundler和gem:
gem install bundler
bundle install
由于本机扩展(即nokogiri等)而必须构建的大多数宝石安装正确但我有memcached gem的问题。构建gem失败,出现以下错误:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. [7/1778]
/usr/bin/ruby1.9.1 extconf.rb
extconf.rb:7: Use RbConfig instead of obsolete and deprecated Config.
Touching all files so autoconf doesn't run.
find . | xargs touch
Configuring libmemcached.
env CFLAGS='-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC -g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC' LDFLAGS='-fPIC -L. -Wl,-Bsymbolic-functions -Wl,-z,relro
-L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib
-rdynamic -Wl,-export-dynamic -L/usr/lib' ./configure --prefix=/bundler-cache/gems/memcached-1.4.6/ext --without-memcached --disable-shared --disable-utils
--disable-dependency-tracking CC="gcc" 2>&1
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... configure: error: newly created file is older than distributed files!
Check your system clock
extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.9.1
extconf.rb:35:in `run': 'env CFLAGS='-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC -g -O2
-fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC' LDFLAGS='-fPIC -L. -Wl,-Bsymbolic-functions -Wl,-z,relro
-L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib
-rdynamic -Wl,-export-dynamic -L/usr/lib' ./configure --prefix=/bundler-cache/gems/memcached-1.4.6/ext --without-memcached --disable-shared --disable-utils
--disable-dependency-tracking CC="gcc" 2>&1' failed (RuntimeError)
from extconf.rb:52:in `block (2 levels) in check_libmemcached'
from extconf.rb:50:in `chdir'
from extconf.rb:50:in `block in check_libmemcached'
from extconf.rb:49:in `chdir'
from extconf.rb:49:in `check_libmemcached'
from extconf.rb:69:in `<main>'
Gem files will remain installed in /bundler-cache/gems/memcached-1.4.6 for inspection.
Results logged to /bundler-cache/gems/memcached-1.4.6/ext/gem_make.out
错误是由memcached gem的extconf.rb文件中的以下行引起的:
run("env CFLAGS='-fPIC #{LIBM_CFLAGS}' LDFLAGS='-fPIC #{LIBM_LDFLAGS}' ./configure --prefix=#{HERE} --without-memcached --disable-shared --disable-utils --disable-dependency-tracking #{$CC} #{$EXTRA_CONF} 2>&1", "Configuring libmemcached.")
但是,如果我仍然在容器的bash上进入/bundler-cache/gems/memcached-1.4.6/ext/libmemcached-0.32
文件夹并执行上述命令的扩展版本:
env CFLAGS='-fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall -fno-strict-aliasing -fPIC' LDFLAGS='-fPIC -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -L/build/buildd/ruby1.9.1-1.9.3.484/debian/lib -rdynamic -Wl,-export-dynamic -L/usr/lib' ./configure --prefix=/bundler-cache/gems/memcached-1.4.6/ext --without-memcached --disable-shared --disable-utils --disable-dependency-tracking CC="gcc" 2>&1
一切顺利,没有任何问题。有没有人知道为什么会发生这种情况?如果出现问题,如何通过修复gem安装或适当的音量安装来解决这个问题?