如何将已安装的宝石复制到另一个泊坞窗图像?

时间:2017-10-24 04:06:09

标签: ruby-on-rails ruby docker

我尝试使用Docker多阶段构建来为rails生产运行时创建一个干净的图像。 我制作了像下面的Dockerfile

# Build image
FROM scardon/ruby-node-alpine:2.4.2 AS build-env

COPY Gemfile* ./
RUN apk update && \
    apk add --no-cache --virtual build-dependencies PACKAGES && \
    gem install bundler && \
    bundle install && \
    bundle exec assets:precompile && \
    bundle exec assets:sync

# Runtime image
FROM ruby:2.4.2-alpine3.6

COPY . .
# $BUNLE_PATH is set to /usr/local/bundle in both images.
COPY --from=build-env /usr/local/bundle /usr/local/bundle
COPY --from=build-env /root/public/assets/.sprockets-manifest-abcdef123456.json /root/public/assets/.sprockets-manifest-abcdef123456.json

但是在下图中,bundle check表示未安装需要原生扩展构建的gem。 bundle doctor输出如下所示

Ignoring bindex-0.5.0 because its extensions are not built.  Try: gem pristine bindex --version 0.5.0
Ignoring binding_of_caller-0.7.2 because its extensions are not built.  Try: gem pristine binding_of_caller --version 0.7.2
Ignoring byebug-9.0.6 because its extensions are not built.  Try: gem pristine byebug --version 9.0.6
Ignoring debug_inspector-0.0.3 because its extensions are not built.  Try: gem pristine debug_inspector --version 0.0.3
Ignoring ffi-1.9.18 because its extensions are not built.  Try: gem pristine ffi --version 1.9.18
Ignoring json-2.1.0 because its extensions are not built.  Try: gem pristine json --version 2.1.0
Ignoring mysql2-0.4.8 because its extensions are not built.  Try: gem pristine mysql2 --version 0.4.8
Ignoring nio4r-2.1.0 because its extensions are not built.  Try: gem pristine nio4r --version 2.1.0
Ignoring nokogiri-1.8.0 because its extensions are not built.  Try: gem pristine nokogiri --version 1.8.0
Ignoring oj-3.3.4 because its extensions are not built.  Try: gem pristine oj --version 3.3.4
Ignoring puma-3.9.1 because its extensions are not built.  Try: gem pristine puma --version 3.9.1
Ignoring rainbow-2.2.2 because its extensions are not built.  Try: gem pristine rainbow --version 2.2.2
Ignoring websocket-driver-0.6.5 because its extensions are not built.  Try: gem pristine websocket-driver --version 0.6.5
The latest bundler is 1.16.0.pre.3, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
The following gems are missing
 * nokogiri (1.8.0)
 * nio4r (2.1.0)
 * websocket-driver (0.6.5)
 * bindex (0.5.0)
 * debug_inspector (0.0.3)
 * binding_of_caller (0.7.2)
 * byebug (9.0.6)
 * ffi (1.9.18)
 * rainbow (2.2.2)
 * json (2.1.0)
 * mysql2 (0.4.8)
 * oj (3.3.4)
 * puma (3.9.1)
Install missing gems with `bundle install`

但在$BUNDLE_PATH中,这些宝石就在那里。 需要告诉bundler是否满足依赖关系?

谢谢

(抱歉我的英语不好。)

1 个答案:

答案 0 :(得分:-1)

您可以通过创建持久性Ruby gems容器来共享数据。查看以下详细信息;

https://www.healthcareblocks.com/blog/persistent-ruby-gems-docker-container