gpt4 book ai didi

ruby-on-rails - 无法在 dockerized rails 应用程序中从 git 安装 gems

转载 作者:行者123 更新时间:2023-12-04 06:25:20 25 4
gpt4 key购买 nike

请帮助我构建我的第一个 docker 镜像。
我的 Gemfile包含:

gem 'webpacker', github: 'rails/webpacker'

这是 Dockerfile :
FROM ruby:2.4-alpine

...
ADD Gemfile $INSTALL_PATH/Gemfile
ADD Gemfile.lock $INSTALL_PATH/Gemfile.lock
RUN bundle install
ADD . $INSTALL_PATH
...

Docker 和 docker-compose:
Docker version 17.03.1-ce, build c6d412e
docker-compose version 1.13.0, build 1719ceb

当我跑
docker build .

我收到错误:
Fetching https://github.com/rails/webpacker.git
sh: git: not found

Git error: command `git clone 'https://github.com/rails/webpacker.git'
"/usr/local/bundle/cache/bundler/git/webpacker-
61415c05b31197242a5fde705ba334f36321be12"
--bare --no-hardlinks --quiet` in directory /test_task has failed.

我想,原因与 github 源有关,因为如果我从 Gemfile 中删除所有带有 github 源的 gem,那么将从 ruby​​gems 存储库中正确获取 gem

更新 : 当我使用 ruby:2.4-slim而不是 alpine linux 作为基础镜像,然后构建完成且没有错误

最佳答案

容器内似乎没有 git 。要将其安装在 Alpine 镜像上,您应该在 Dockerfile 中添加以下内容:

FROM ruby:2.4-alpine
RUN apk update && apk add git
... the rest of your Dockerfile ...

希望能帮助到你。

关于ruby-on-rails - 无法在 dockerized rails 应用程序中从 git 安装 gems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43810502/

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