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

标签 ruby-on-rails docker

请帮助我构建我的第一个 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/

相关文章:

css - 画一个圆圈,里面放个人资料照片

ruby-on-rails - 为什么 db :migrate failing when i try to add attachment fields for paperclip?

java - java.lang.ArrayIndexOutOfBoundsException错误Hadoop MapReduce进程

docker - 从镜像创建 Docker 容器而不启动它

docker - 当容器开始使用Dockerfile时如何触摸文件

docker - Windows容器上的Docker容器ID

docker - 集群化的Docker,由Swarm管理

ruby-on-rails - Rails 中的动态常量定义

ruby-on-rails - 如果 Unicorn 启动新进程失败,Capistrano 能通知我吗

ruby-on-rails - Rails 中的 REST API 参数验证