无法在dockerized rails应用程序中从git安装gem

请帮助我build立我的第一个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工人:

 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,那么gem将被正确地从rubygems存储库

更新 :当我使用ruby:2.4-slim而不是alpine linux作为基础的形象,然后构build完成没有错误

看来你没有在容器内的git。 要将其安装在Alpine图片上,您应该添加到您的Dockerfile中:

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

希望能帮助到你。