gpt4 book ai didi

ruby-on-rails - 如何将已安装的 gem 复制到另一个 docker 镜像?

转载 作者:数据小太阳 更新时间:2023-10-29 08:13:57 30 4
gpt4 key购买 nike

我尝试了 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 表示未安装需要原生扩展构建的 gems。 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 中,这些 gem 就在那里。需要什么来告诉 bundler 依赖关系已满足?

谢谢

(抱歉我的英语不好。)

最佳答案

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

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

关于ruby-on-rails - 如何将已安装的 gem 复制到另一个 docker 镜像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46902009/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com