2017-05-05 104 views
4

請幫助我構建我的第一個碼頭圖像。 我Gemfile contails:無法在dockerized rails應用程序中從git安裝寶石

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 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源中的所有寶石,則寶石會被正確地從RubyGems的倉庫

UPD取:當我使用ruby:2.4-slim而不是alpine Linux作爲基礎映像,然後構建完成沒有錯誤

回答

4

看來你沒有在容器內的git。要阿爾卑斯映像上安裝它,您應該添加到您的Dockerfile這樣的:

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

希望它能幫助。